diff options
author | Sergio Queiroz <sqmedeiros@gmail.com> | 2019-01-10 10:06:33 -0300 |
---|---|---|
committer | Sergio Queiroz <sqmedeiros@gmail.com> | 2019-01-10 10:06:33 -0300 |
commit | 4fb816d55f47c48c34cc4478e584b1567a75863b (patch) | |
tree | 54ec6965c9d3983b193cf000a521a06cb3d73b8a /test.lua | |
parent | 9be59fb8f4b176a16643e707c74051b243202296 (diff) | |
download | lpeglabel-lpeg-1.0.0.tar.gz lpeglabel-lpeg-1.0.0.tar.bz2 lpeglabel-lpeg-1.0.0.zip |
Adapting lpeglabel-1.5 to the codebase of lpeg-1.0.0lpeg-1.0.0
Diffstat (limited to 'test.lua')
-rwxr-xr-x | test.lua | 57 |
1 files changed, 1 insertions, 56 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,v 1.109 2015/09/28 17:01:25 roberto Exp $ |
4 | 4 | ||
5 | -- require"strict" -- just to be pedantic | 5 | -- require"strict" -- just to be pedantic |
6 | 6 | ||
@@ -202,14 +202,6 @@ do | |||
202 | end | 202 | end |
203 | 203 | ||
204 | 204 | ||
205 | -- bug: loop in 'hascaptures' | ||
206 | do | ||
207 | local p = m.C(-m.P{m.P'x' * m.V(1) + m.P'y'}) | ||
208 | assert(p:match("xxx") == "") | ||
209 | end | ||
210 | |||
211 | |||
212 | |||
213 | -- test for small capture boundary | 205 | -- test for small capture boundary |
214 | for i = 250,260 do | 206 | for i = 250,260 do |
215 | assert(#m.match(m.C(i), string.rep('a', i)) == i) | 207 | assert(#m.match(m.C(i), string.rep('a', i)) == i) |
@@ -525,27 +517,6 @@ assert(m.match(m.Cs((#((#m.P"a")/"") * 1 + m.P(1)/".")^0), "aloal") == "a..a.") | |||
525 | assert(m.match(m.Cs((- -m.P("a") * 1 + m.P(1)/".")^0), "aloal") == "a..a.") | 517 | assert(m.match(m.Cs((- -m.P("a") * 1 + m.P(1)/".")^0), "aloal") == "a..a.") |
526 | assert(m.match(m.Cs((-((-m.P"a")/"") * 1 + m.P(1)/".")^0), "aloal") == "a..a.") | 518 | assert(m.match(m.Cs((-((-m.P"a")/"") * 1 + m.P(1)/".")^0), "aloal") == "a..a.") |
527 | 519 | ||
528 | |||
529 | -- fixed length | ||
530 | do | ||
531 | -- 'and' predicate using fixed length | ||
532 | local p = m.C(#("a" * (m.P("bd") + "cd")) * 2) | ||
533 | assert(p:match("acd") == "ac") | ||
534 | |||
535 | p = #m.P{ "a" * m.V(2), m.P"b" } * 2 | ||
536 | assert(p:match("abc") == 3) | ||
537 | |||
538 | p = #(m.P"abc" * m.B"c") | ||
539 | assert(p:match("abc") == 1 and not p:match("ab")) | ||
540 | |||
541 | p = m.P{ "a" * m.V(2), m.P"b"^1 } | ||
542 | checkerr("pattern may not have fixed length", m.B, p) | ||
543 | |||
544 | p = "abc" * (m.P"b"^1 + m.P"a"^0) | ||
545 | checkerr("pattern may not have fixed length", m.B, p) | ||
546 | end | ||
547 | |||
548 | |||
549 | p = -m.P'a' * m.Cc(1) + -m.P'b' * m.Cc(2) + -m.P'c' * m.Cc(3) | 520 | p = -m.P'a' * m.Cc(1) + -m.P'b' * m.Cc(2) + -m.P'c' * m.Cc(3) |
550 | assert(p:match('a') == 2 and p:match('') == 1 and p:match('b') == 1) | 521 | assert(p:match('a') == 2 and p:match('') == 1 and p:match('b') == 1) |
551 | 522 | ||
@@ -1127,32 +1098,6 @@ do | |||
1127 | assert(c == 11) | 1098 | assert(c == 11) |
1128 | end | 1099 | end |
1129 | 1100 | ||
1130 | |||
1131 | -- Return a match-time capture that returns 'n' captures | ||
1132 | local function manyCmt (n) | ||
1133 | return m.Cmt("a", function () | ||
1134 | local a = {}; for i = 1, n do a[i] = n - i end | ||
1135 | return true, unpack(a) | ||
1136 | end) | ||
1137 | end | ||
1138 | |||
1139 | -- bug in 1.0: failed match-time that used previous match-time results | ||
1140 | do | ||
1141 | local x | ||
1142 | local function aux (...) x = #{...}; return false end | ||
1143 | local res = {m.match(m.Cmt(manyCmt(20), aux) + manyCmt(10), "a")} | ||
1144 | assert(#res == 10 and res[1] == 9 and res[10] == 0) | ||
1145 | end | ||
1146 | |||
1147 | |||
1148 | -- bug in 1.0: problems with math-times returning too many captures | ||
1149 | do | ||
1150 | local lim = 2^11 - 10 | ||
1151 | local res = {m.match(manyCmt(lim), "a")} | ||
1152 | assert(#res == lim and res[1] == lim - 1 and res[lim] == 0) | ||
1153 | checkerr("too many", m.match, manyCmt(2^15), "a") | ||
1154 | end | ||
1155 | |||
1156 | p = (m.P(function () return true, "a" end) * 'a' | 1101 | p = (m.P(function () return true, "a" end) * 'a' |
1157 | + m.P(function (s, i) return i, "aa", 20 end) * 'b' | 1102 | + m.P(function (s, i) return i, "aa", 20 end) * 'b' |
1158 | + m.P(function (s,i) if i <= #s then return i, "aaa" end end) * 1)^0 | 1103 | + m.P(function (s,i) if i <= #s then return i, "aaa" end end) * 1)^0 |