aboutsummaryrefslogtreecommitdiff
path: root/testlabel.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testlabel.lua')
-rw-r--r--testlabel.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/testlabel.lua b/testlabel.lua
index 4f0768d..6ae184f 100644
--- a/testlabel.lua
+++ b/testlabel.lua
@@ -2,6 +2,15 @@ local m = require 'lpeglabel'
2 2
3local p, r, l, s, serror 3local p, r, l, s, serror
4 4
5local function checkeqlab (x, ...)
6 y = { ... }
7 assert(type(x) == "table")
8 assert(#x == #y)
9 for i = 1, 3 do
10 assert(x[i] == y[i])
11 end
12end
13
5-- throws a label 14-- throws a label
6p = m.T(1) 15p = m.T(1)
7s = "abc" 16s = "abc"
@@ -538,4 +547,31 @@ A := a;]]
538assert(g:match(s) == terror['undefined']) 547assert(g:match(s) == terror['undefined'])
539 548
540 549
550print("+")
551
552
553-- test recovery operator
554p = m.Rec("a", "b")
555assert(p:match("a") == 2)
556assert(p:match("b") == 2)
557checkeqlab({nil, 0, "c"}, p:match("c"))
558
559p = m.Rec("a", "b", 3)
560assert(p:match("a") == 2)
561checkeqlab({nil, 0, "b"}, p:match("b"))
562checkeqlab({nil, 0, "c"}, p:match("c"))
563
564p = m.Rec(m.T(3), "b")
565checkeqlab({nil, 3, "a"}, p:match("a"))
566checkeqlab({nil, 3, "b"}, p:match("b"))
567
568p = m.Rec(m.T(3), "b", 3)
569p:pcode()
570checkeqlab({nil, 0, "a"}, p:match("a"))
571assert(p:match("b") == 2)
572
573
541print("OK") 574print("OK")
575
576
577