aboutsummaryrefslogtreecommitdiff
path: root/test.lua
diff options
context:
space:
mode:
authorSergio <sqmedeiros@gmail.com>2019-06-21 18:07:07 -0300
committerSergio <sqmedeiros@gmail.com>2019-06-21 18:07:07 -0300
commit0671e873f50ba568074d1683e068d5dce88dd43b (patch)
tree373f46d1c3fac997803835155a5ba764bbcbd250 /test.lua
parent0f48dada44ec37bec8ef1b44ef8b621716ca5c05 (diff)
downloadlpeglabel-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-xtest.lua22
1 files changed, 21 insertions, 1 deletions
diff --git a/test.lua b/test.lua
index a3b86bf..2c05dd0 100755
--- a/test.lua
+++ b/test.lua
@@ -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
424end 424end
425 425
426 426
427do
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")
434end
435
436
427-- tests for non-pattern as arguments to pattern functions 437-- tests for non-pattern as arguments to pattern functions
428 438
429p = { ('a' * m.V(1))^-1 } * m.P'b' * { 'a' * m.V(2); m.V(1)^-1 } 439p = { ('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] + "))
1186assert(match("abb\"de", '"abb"["]"de"') == 7) 1196assert(match("abb\"de", '"abb"["]"de"') == 7)
1187assert(match("abceeef", "'ac' ? 'ab' * 'c' { 'e' * } / 'abceeef' ") == "eee") 1197assert(match("abceeef", "'ac' ? 'ab' * 'c' { 'e' * } / 'abceeef' ") == "eee")
1188assert(match("abceeef", "'ac'? 'ab'* 'c' { 'f'+ } / 'abceeef' ") == 8) 1198assert(match("abceeef", "'ac'? 'ab'* 'c' { 'f'+ } / 'abceeef' ") == 8)
1199
1200assert(re.match("aaand", "[a]^2") == 3)
1201
1189local t = {match("abceefe", "( ( & 'e' {} ) ? . ) * ")} 1202local t = {match("abceefe", "( ( & 'e' {} ) ? . ) * ")}
1190checkeq(t, {4, 5, 7}) 1203checkeq(t, {4, 5, 7})
1191local t = {match("abceefe", "((&&'e' {})? .)*")} 1204local 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
1377c = re.compile([[
1378 S <- (number (%s+ number)*) ~> add
1379 number <- %d+ -> tonumber
1380]], {tonumber = tonumber, add = function (a,b) return a + b end})
1381assert(c:match("3 401 50") == 3 + 401 + 50)
1382
1363-- tests for look-ahead captures 1383-- tests for look-ahead captures
1364x = {re.match("alo", "&(&{.}) !{'b'} {&(...)} &{..} {...} {!.}")} 1384x = {re.match("alo", "&(&{.}) !{'b'} {&(...)} &{..} {...} {!.}")}
1365checkeq(x, {"", "alo", ""}) 1385checkeq(x, {"", "alo", ""})