From 2096a27b65af6cb2c5c30d907cd4ad6a4b19bb60 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Tue, 13 Jun 2017 09:11:43 +0200 Subject: [PATCH] test: add translator spec (#2953) --- spec/unit/translator_spec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/unit/translator_spec.lua diff --git a/spec/unit/translator_spec.lua b/spec/unit/translator_spec.lua new file mode 100644 index 000000000..65b2b7028 --- /dev/null +++ b/spec/unit/translator_spec.lua @@ -0,0 +1,27 @@ +local dutch_wikipedia_text = "Wikipedia is een meertalige encyclopedie, waarvan de inhoud vrij beschikbaar is. Iedereen kan hier kennis toevoegen!" + +describe("Translator module", function() + setup(function() + require("commonrequire") + Translator = require("ui/translator") + end) + it("should return server", function() + assert.is.same("http://translate.google.cn", Translator:getTransServer()) + G_reader_settings:saveSetting("trans_server", "http://translate.google.nl") + G_reader_settings:flush() + assert.is.same("http://translate.google.nl", Translator:getTransServer()) + G_reader_settings:delSetting("trans_server") + G_reader_settings:flush() + end) + it("should return translation #notest #nocov", function() + local translation_result = Translator:loadPage("en", "nl", dutch_wikipedia_text) + assert.is.truthy(translation_result) + -- while some minor variation in the translation is possible it should + -- be between about 100 and 130 characters + assert.is_true(#translation_result > 50 and #translation_result < 200) + end) + it("should autodetect language #notest #nocov", function() + local detect_result = Translator:detect(dutch_wikipedia_text) + assert.is.same("nl", detect_result) + end) +end)