From ca87afc26f35bcbc74d81da9118b8b67c5192371 Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Fri, 29 Dec 2023 21:12:53 +0100 Subject: poconvert: minor refactor; add unittest poconvert.lua now recognizes fuzzy entries in PO files; these entries are also added to the target file, but they are prefixed with "#" (i.e. marked as comments). --- advtrains/spec/poconvert_spec.lua | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 advtrains/spec/poconvert_spec.lua (limited to 'advtrains/spec') diff --git a/advtrains/spec/poconvert_spec.lua b/advtrains/spec/poconvert_spec.lua new file mode 100644 index 0000000..ef87619 --- /dev/null +++ b/advtrains/spec/poconvert_spec.lua @@ -0,0 +1,68 @@ +package.path = "../?.lua;" .. package.path +advtrains = {} +_G.advtrains = advtrains +local poconvert = require("poconvert") + +describe("PO file converter", function() + it("should convert PO files", function() + assert.equals([[ +# textdomain: foo +foo=bar +baz= +#@=wh\at\@n=@=w\as\@n +multiline@nstrings= +with context?=oder doch nicht]], poconvert.from_string("foo", [[ +msgid "" +msgstr "whatever metadata" + +msgid "foo" +msgstr "bar" + +msgid "baz" +msgstr "" + +#, fuzzy +msgid "=wh\\at\\\n" +msgstr "=w\\as\\\n" + +msgid "multi" +"line\n" +"strings" +msgstr "" + +msgctxt "i18n context" +msgid "with context?" +msgstr "oder doch nicht"]])) + end) + it("should reject invalid tokens", function() + assert.has.errors(function() + poconvert.from_string("", [[ +foo "" +bar ""]]) + end, "Invalid token: foo") + end) + it("should reject entries without a msgstr", function() + assert.has.errors(function() + poconvert.from_string("", [[msgid "foo"]]) + end, "Missing translated string") + end) + it("should reject entries without a msgid", function() + assert.has.errors(function() + poconvert.from_string("", [[msgstr "foo"]]) + end, "Missing untranslated string") + end) + it("should reject entries with improperly enclosed strings", function() + assert.has.errors(function() + poconvert.from_string("", [[ +msgid "foo" +msgstr "bar \]]) + end, "String extends beyond the end of input") + end) + it("should reject incomplete input", function() + assert.has.errors(function() + poconvert.from_string("", [[ +msgid "foo" +msgstr]]) + end, "No string provided for msgstr") + end) +end) -- cgit v1.2.3