-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
sil_spec.lua
103 lines (85 loc) · 3.52 KB
/
sil_spec.lua
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
SILE = require("core.sile")
SILE.backend = "dummy"
SILE.init()
SILE.utilities.error = error
describe("#SIL #inputter", function ()
local inputter = SILE.inputters.sil()
describe("should parse", function ()
it("commands with content", function()
local t = inputter:parse([[\foo{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("bar", t[1][1])
end)
it("commands without content", function()
local t = inputter:parse([[\foo{\foo bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("foo", t[1][1].command)
assert.is.equal(" bar", t[1][2])
assert.is.equal(nil, t[1][1][1])
end)
it("commands with arg", function()
local t = inputter:parse([[\foo[baz=qiz]{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("qiz", t.options.baz)
assert.is.equal("bar", t[1][1])
end)
it("commands with multiple args", function()
local t = inputter:parse([[\foo[baz=qiz,qiz=baz]{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("qiz", t.options.baz)
assert.is.equal("baz", t.options.qiz)
assert.is.equal("bar", t[1][1])
end)
it("commands with quoted arg", function()
local t = inputter:parse([[\foo[baz="qiz qiz"]{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("qiz qiz", t.options.baz)
assert.is.equal("bar", t[1][1])
end)
it("commands with space around args and values", function()
local t = inputter:parse([[\foo[ baz = qiz qiz ]{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("qiz qiz", t.options.baz)
end)
it("commands with multiple quoted args", function()
local t = inputter:parse([[\foo[baz="qiz, qiz",qiz="baz, baz"]{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("qiz, qiz", t.options.baz)
assert.is.equal("baz, baz", t.options.qiz)
assert.is.equal("bar", t[1][1])
end)
it("commands with quoted arg with escape", function()
local t = inputter:parse([[\foo[baz="qiz \"qiz\""]{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("qiz \"qiz\"", t.options.baz)
assert.is.equal("bar", t[1][1])
end)
it("fragments with multiple top level nodes", function()
local t = inputter:parse([[foo \bar{bar}]])[1]
assert.is.equal("document", t.command)
assert.is.equal("foo ", t[1][1])
assert.is.equal("bar", t[1][2].command)
assert.is.equal("bar", t[1][2][1][1])
end)
end)
describe("should reject", function ()
it("commands with bad characters", function()
local pattern = "parse error, Unexpected character at end of input"
assert.has_error.match(function() inputter:parse([[\"]]) end, pattern)
assert.has_error.match(function() inputter:parse([[\']]) end, pattern)
assert.has_error.match(function() inputter:parse([[\"o]]) end, pattern)
end)
it("unclosed commands", function()
assert.has_error.matches(function() inputter:parse([[\foo{bar]]) end,
"parse error at <eof>, %} expected")
end)
it("unclosed environments", function()
assert.has_error.matches(function() inputter:parse([[\begin{foo}bar]]) end,
"parse error at <eof>, Environment begun but never ended")
end)
it("mismatched environments", function()
assert.has_error.matches(function() inputter:parse([[\begin{foo}\begin{bar}baz\end{foo}\end{bar}]]) end,
"parse error, Environment mismatch")
end)
end)
end)