diff options
author | Y. Wang <yw05@forksworld.de> | 2023-12-29 21:12:53 +0100 |
---|---|---|
committer | Y. Wang <yw05@forksworld.de> | 2024-04-13 10:36:35 +0200 |
commit | ca87afc26f35bcbc74d81da9118b8b67c5192371 (patch) | |
tree | 0e74e8cc086eb844b2c86431a6610af328f62411 /advtrains/spec | |
parent | b8466d4abb0c8d639e396861d7635ed90b4718e1 (diff) | |
download | advtrains-ca87afc26f35bcbc74d81da9118b8b67c5192371.tar.gz advtrains-ca87afc26f35bcbc74d81da9118b8b67c5192371.tar.bz2 advtrains-ca87afc26f35bcbc74d81da9118b8b67c5192371.zip |
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).
Diffstat (limited to 'advtrains/spec')
-rw-r--r-- | advtrains/spec/poconvert_spec.lua | 68 |
1 files changed, 68 insertions, 0 deletions
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) |