aboutsummaryrefslogtreecommitdiff
path: root/advtrains/spec
diff options
context:
space:
mode:
authorY. Wang <yw05@forksworld.de>2023-10-04 20:07:24 +0200
committerY. Wang <y5nw@protonmail.com>2024-11-04 17:17:51 +0100
commit425b0993d355b9f45ddd400bd4925f9f1a5bd34d (patch)
tree77a105e5bbf28c03e31c5c30e5866387d618e174 /advtrains/spec
parentbed66e0f901ae9f8e21675035f174292120fea4f (diff)
downloadadvtrains-425b0993d355b9f45ddd400bd4925f9f1a5bd34d.tar.gz
advtrains-425b0993d355b9f45ddd400bd4925f9f1a5bd34d.tar.bz2
advtrains-425b0993d355b9f45ddd400bd4925f9f1a5bd34d.zip
Autogenerate .tr files from .po files
Diffstat (limited to 'advtrains/spec')
-rw-r--r--advtrains/spec/poconvert_spec.lua70
1 files changed, 70 insertions, 0 deletions
diff --git a/advtrains/spec/poconvert_spec.lua b/advtrains/spec/poconvert_spec.lua
new file mode 100644
index 0000000..51f33e7
--- /dev/null
+++ b/advtrains/spec/poconvert_spec.lua
@@ -0,0 +1,70 @@
+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=multiline@nresult
+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 "multi"
+"line\n"
+"result"
+
+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)