aboutsummaryrefslogtreecommitdiff
path: root/advtrains/spec/poconvert_spec.lua
blob: 51f33e7c4982799b2d937752c5d6a2ac13a679dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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)