diff options
author | Sergio <sqmedeiros@gmail.com> | 2019-06-21 18:07:07 -0300 |
---|---|---|
committer | Sergio <sqmedeiros@gmail.com> | 2019-06-21 18:07:07 -0300 |
commit | 0671e873f50ba568074d1683e068d5dce88dd43b (patch) | |
tree | 373f46d1c3fac997803835155a5ba764bbcbd250 /test.lua | |
parent | 0f48dada44ec37bec8ef1b44ef8b621716ca5c05 (diff) | |
download | lpeglabel-0671e873f50ba568074d1683e068d5dce88dd43b.tar.gz lpeglabel-0671e873f50ba568074d1683e068d5dce88dd43b.tar.bz2 lpeglabel-0671e873f50ba568074d1683e068d5dce88dd43b.zip |
Updating LPegLabel to the codebase of LPeg 1.0.2
Diffstat (limited to 'test.lua')
-rwxr-xr-x | test.lua | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/env lua | 1 | #!/usr/bin/env lua |
2 | 2 | ||
3 | -- $Id: test.lua,v 1.112 2017/01/14 18:55:22 roberto Exp $ | 3 | -- $Id: test.lua $ |
4 | 4 | ||
5 | -- require"strict" -- just to be pedantic | 5 | -- require"strict" -- just to be pedantic |
6 | 6 | ||
@@ -424,6 +424,16 @@ do | |||
424 | end | 424 | end |
425 | 425 | ||
426 | 426 | ||
427 | do | ||
428 | -- nesting of captures too deep | ||
429 | local p = m.C(1) | ||
430 | for i = 1, 300 do | ||
431 | p = m.Ct(p) | ||
432 | end | ||
433 | checkerr("too deep", p.match, p, "x") | ||
434 | end | ||
435 | |||
436 | |||
427 | -- tests for non-pattern as arguments to pattern functions | 437 | -- tests for non-pattern as arguments to pattern functions |
428 | 438 | ||
429 | p = { ('a' * m.V(1))^-1 } * m.P'b' * { 'a' * m.V(2); m.V(1)^-1 } | 439 | p = { ('a' * m.V(1))^-1 } * m.P'b' * { 'a' * m.V(2); m.V(1)^-1 } |
@@ -1186,6 +1196,9 @@ assert(not match("abbcde", " [b-z] + ")) | |||
1186 | assert(match("abb\"de", '"abb"["]"de"') == 7) | 1196 | assert(match("abb\"de", '"abb"["]"de"') == 7) |
1187 | assert(match("abceeef", "'ac' ? 'ab' * 'c' { 'e' * } / 'abceeef' ") == "eee") | 1197 | assert(match("abceeef", "'ac' ? 'ab' * 'c' { 'e' * } / 'abceeef' ") == "eee") |
1188 | assert(match("abceeef", "'ac'? 'ab'* 'c' { 'f'+ } / 'abceeef' ") == 8) | 1198 | assert(match("abceeef", "'ac'? 'ab'* 'c' { 'f'+ } / 'abceeef' ") == 8) |
1199 | |||
1200 | assert(re.match("aaand", "[a]^2") == 3) | ||
1201 | |||
1189 | local t = {match("abceefe", "( ( & 'e' {} ) ? . ) * ")} | 1202 | local t = {match("abceefe", "( ( & 'e' {} ) ? . ) * ")} |
1190 | checkeq(t, {4, 5, 7}) | 1203 | checkeq(t, {4, 5, 7}) |
1191 | local t = {match("abceefe", "((&&'e' {})? .)*")} | 1204 | local t = {match("abceefe", "((&&'e' {})? .)*")} |
@@ -1360,6 +1373,13 @@ checkeq(x, {tag='x', 'hi', {tag = 'b', 'hello'}, 'but', | |||
1360 | {'totheend'}}) | 1373 | {'totheend'}}) |
1361 | 1374 | ||
1362 | 1375 | ||
1376 | -- test for folding captures | ||
1377 | c = re.compile([[ | ||
1378 | S <- (number (%s+ number)*) ~> add | ||
1379 | number <- %d+ -> tonumber | ||
1380 | ]], {tonumber = tonumber, add = function (a,b) return a + b end}) | ||
1381 | assert(c:match("3 401 50") == 3 + 401 + 50) | ||
1382 | |||
1363 | -- tests for look-ahead captures | 1383 | -- tests for look-ahead captures |
1364 | x = {re.match("alo", "&(&{.}) !{'b'} {&(...)} &{..} {...} {!.}")} | 1384 | x = {re.match("alo", "&(&{.}) !{'b'} {&(...)} &{..} {...} {!.}")} |
1365 | checkeq(x, {"", "alo", ""}) | 1385 | checkeq(x, {"", "alo", ""}) |