mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 11:33:09 +00:00
update lpeg to 1.0.2 (#1557)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env lua
|
||||
|
||||
-- $Id: test.lua,v 1.112 2017/01/14 18:55:22 roberto Exp $
|
||||
-- $Id: test.lua $
|
||||
|
||||
-- require"strict" -- just to be pedantic
|
||||
|
||||
@@ -424,6 +424,16 @@ do
|
||||
end
|
||||
|
||||
|
||||
do
|
||||
-- nesting of captures too deep
|
||||
local p = m.C(1)
|
||||
for i = 1, 300 do
|
||||
p = m.Ct(p)
|
||||
end
|
||||
checkerr("too deep", p.match, p, "x")
|
||||
end
|
||||
|
||||
|
||||
-- tests for non-pattern as arguments to pattern functions
|
||||
|
||||
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] + "))
|
||||
assert(match("abb\"de", '"abb"["]"de"') == 7)
|
||||
assert(match("abceeef", "'ac' ? 'ab' * 'c' { 'e' * } / 'abceeef' ") == "eee")
|
||||
assert(match("abceeef", "'ac'? 'ab'* 'c' { 'f'+ } / 'abceeef' ") == 8)
|
||||
|
||||
assert(re.match("aaand", "[a]^2") == 3)
|
||||
|
||||
local t = {match("abceefe", "( ( & 'e' {} ) ? . ) * ")}
|
||||
checkeq(t, {4, 5, 7})
|
||||
local t = {match("abceefe", "((&&'e' {})? .)*")}
|
||||
@@ -1360,6 +1373,13 @@ checkeq(x, {tag='x', 'hi', {tag = 'b', 'hello'}, 'but',
|
||||
{'totheend'}})
|
||||
|
||||
|
||||
-- test for folding captures
|
||||
c = re.compile([[
|
||||
S <- (number (%s+ number)*) ~> add
|
||||
number <- %d+ -> tonumber
|
||||
]], {tonumber = tonumber, add = function (a,b) return a + b end})
|
||||
assert(c:match("3 401 50") == 3 + 401 + 50)
|
||||
|
||||
-- tests for look-ahead captures
|
||||
x = {re.match("alo", "&(&{.}) !{'b'} {&(...)} &{..} {...} {!.}")}
|
||||
checkeq(x, {"", "alo", ""})
|
||||
|
||||
Reference in New Issue
Block a user