aboutsummaryrefslogtreecommitdiff
path: root/testlabel.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testlabel.lua')
-rw-r--r--testlabel.lua18
1 files changed, 11 insertions, 7 deletions
diff --git a/testlabel.lua b/testlabel.lua
index 1be1343..72eb9aa 100644
--- a/testlabel.lua
+++ b/testlabel.lua
@@ -6,6 +6,9 @@ local function checklabeq (x, ...)
6 y = { ... } 6 y = { ... }
7 assert(type(x) == "table") 7 assert(type(x) == "table")
8 assert(#x == #y) 8 assert(#x == #y)
9 if x[2] == 0 then -- 0 -> 'fail'
10 x[2] = 'fail'
11 end
9 for i = 1, 3 do 12 for i = 1, 3 do
10 assert(x[i] == y[i]) 13 assert(x[i] == y[i])
11 end 14 end
@@ -81,12 +84,12 @@ print"+"
81p = m.T(1) 84p = m.T(1)
82s = "abc" 85s = "abc"
83r, l, poserr = p:match(s) 86r, l, poserr = p:match(s)
84assert(r == nil and l == 1 and poserr == 1) 87assert(r == nil and l == '1' and poserr == 1)
85 88
86-- throws a label, choice does not catch labels 89-- throws a label, choice does not catch labels
87p = m.T(1) + m.P"a" 90p = m.T(1) + m.P"a"
88r, l, poserr = p:match(s) 91r, l, poserr = p:match(s)
89assert(r == nil and l == 1 and poserr == 1) 92assert(r == nil and l == '1' and poserr == 1)
90 93
91-- again throws a label that is not caught by choice 94-- again throws a label that is not caught by choice
92local g = m.P{ 95local g = m.P{
@@ -96,21 +99,22 @@ local g = m.P{
96 B = m.P"a" 99 B = m.P"a"
97} 100}
98r, l, poserr = g:match(s) 101r, l, poserr = g:match(s)
99assert(r == nil and l == 1 and poserr == 1) 102assert(r == nil and l == '1' and poserr == 1)
100 103
101-- throws a label in a position that is not the farthest one 104-- throws a label in a position that is not the farthest one
102-- but it is the position that should be reported 105-- but it is the position that should be reported
103p = m.P(1) * m.P"a" + m.T(11) 106p = m.P(1) * m.P"a" + m.T(11)
104checklabeq({3, nil, nil}, p:match("bac")) 107checklabeq({3, nil, nil}, p:match("bac"))
105checklabeq({nil, 11, 1}, p:match("c")) 108checklabeq({nil, '11', 1}, p:match("c"))
106checklabeq({nil, 11, 1}, p:match("x")) 109checklabeq({nil, '11', 1}, p:match("x"))
107checklabeq({nil, 11, 1}, p:match("kx")) 110checklabeq({nil, '11', 1}, p:match("kx"))
108 111
109 112
110-- throws a label that is not caught by the recovery operator 113-- throws a label that is not caught by the recovery operator
111p = m.Rec(m.T(2), m.P"a", 1, 3) 114p = m.Rec(m.T(2), m.P"a", 1, 3)
112r, l, poserr = p:match(s) 115r, l, poserr = p:match(s)
113assert(r == nil and l == 2 and poserr == 1) 116print(r, l, poserr)
117assert(r == nil and l == '2' and poserr == 1)
114 118
115-- wraps the previous pattern with a recovery that catches label "2" 119-- wraps the previous pattern with a recovery that catches label "2"
116p = m.Rec(p, m.P"a", 2) 120p = m.Rec(p, m.P"a", 2)