diff options
Diffstat (limited to 'testlabel.lua')
-rw-r--r-- | testlabel.lua | 18 |
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"+" | |||
81 | p = m.T(1) | 84 | p = m.T(1) |
82 | s = "abc" | 85 | s = "abc" |
83 | r, l, poserr = p:match(s) | 86 | r, l, poserr = p:match(s) |
84 | assert(r == nil and l == 1 and poserr == 1) | 87 | assert(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 |
87 | p = m.T(1) + m.P"a" | 90 | p = m.T(1) + m.P"a" |
88 | r, l, poserr = p:match(s) | 91 | r, l, poserr = p:match(s) |
89 | assert(r == nil and l == 1 and poserr == 1) | 92 | assert(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 |
92 | local g = m.P{ | 95 | local g = m.P{ |
@@ -96,21 +99,22 @@ local g = m.P{ | |||
96 | B = m.P"a" | 99 | B = m.P"a" |
97 | } | 100 | } |
98 | r, l, poserr = g:match(s) | 101 | r, l, poserr = g:match(s) |
99 | assert(r == nil and l == 1 and poserr == 1) | 102 | assert(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 |
103 | p = m.P(1) * m.P"a" + m.T(11) | 106 | p = m.P(1) * m.P"a" + m.T(11) |
104 | checklabeq({3, nil, nil}, p:match("bac")) | 107 | checklabeq({3, nil, nil}, p:match("bac")) |
105 | checklabeq({nil, 11, 1}, p:match("c")) | 108 | checklabeq({nil, '11', 1}, p:match("c")) |
106 | checklabeq({nil, 11, 1}, p:match("x")) | 109 | checklabeq({nil, '11', 1}, p:match("x")) |
107 | checklabeq({nil, 11, 1}, p:match("kx")) | 110 | checklabeq({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 |
111 | p = m.Rec(m.T(2), m.P"a", 1, 3) | 114 | p = m.Rec(m.T(2), m.P"a", 1, 3) |
112 | r, l, poserr = p:match(s) | 115 | r, l, poserr = p:match(s) |
113 | assert(r == nil and l == 2 and poserr == 1) | 116 | print(r, l, poserr) |
117 | assert(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" |
116 | p = m.Rec(p, m.P"a", 2) | 120 | p = m.Rec(p, m.P"a", 2) |