diff options
Diffstat (limited to 'testlabel.lua')
-rw-r--r-- | testlabel.lua | 36 |
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 | ||
3 | local p, r, l, s, serror | 3 | local p, r, l, s, serror |
4 | 4 | ||
5 | local 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 | ||
12 | end | ||
13 | |||
5 | -- throws a label | 14 | -- throws a label |
6 | p = m.T(1) | 15 | p = m.T(1) |
7 | s = "abc" | 16 | s = "abc" |
@@ -538,4 +547,31 @@ A := a;]] | |||
538 | assert(g:match(s) == terror['undefined']) | 547 | assert(g:match(s) == terror['undefined']) |
539 | 548 | ||
540 | 549 | ||
550 | print("+") | ||
551 | |||
552 | |||
553 | -- test recovery operator | ||
554 | p = m.Rec("a", "b") | ||
555 | assert(p:match("a") == 2) | ||
556 | assert(p:match("b") == 2) | ||
557 | checkeqlab({nil, 0, "c"}, p:match("c")) | ||
558 | |||
559 | p = m.Rec("a", "b", 3) | ||
560 | assert(p:match("a") == 2) | ||
561 | checkeqlab({nil, 0, "b"}, p:match("b")) | ||
562 | checkeqlab({nil, 0, "c"}, p:match("c")) | ||
563 | |||
564 | p = m.Rec(m.T(3), "b") | ||
565 | checkeqlab({nil, 3, "a"}, p:match("a")) | ||
566 | checkeqlab({nil, 3, "b"}, p:match("b")) | ||
567 | |||
568 | p = m.Rec(m.T(3), "b", 3) | ||
569 | p:pcode() | ||
570 | checkeqlab({nil, 0, "a"}, p:match("a")) | ||
571 | assert(p:match("b") == 2) | ||
572 | |||
573 | |||
541 | print("OK") | 574 | print("OK") |
575 | |||
576 | |||
577 | |||