aboutsummaryrefslogtreecommitdiff
path: root/test.lua
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2019-01-10 10:06:33 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2019-01-10 10:06:33 -0300
commit4fb816d55f47c48c34cc4478e584b1567a75863b (patch)
tree54ec6965c9d3983b193cf000a521a06cb3d73b8a /test.lua
parent9be59fb8f4b176a16643e707c74051b243202296 (diff)
downloadlpeglabel-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-xtest.lua57
1 files changed, 1 insertions, 56 deletions
diff --git a/test.lua b/test.lua
index a3b86bf..d5922ac 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,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
202end 202end
203 203
204 204
205-- bug: loop in 'hascaptures'
206do
207 local p = m.C(-m.P{m.P'x' * m.V(1) + m.P'y'})
208 assert(p:match("xxx") == "")
209end
210
211
212
213-- test for small capture boundary 205-- test for small capture boundary
214for i = 250,260 do 206for 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.")
525assert(m.match(m.Cs((- -m.P("a") * 1 + m.P(1)/".")^0), "aloal") == "a..a.") 517assert(m.match(m.Cs((- -m.P("a") * 1 + m.P(1)/".")^0), "aloal") == "a..a.")
526assert(m.match(m.Cs((-((-m.P"a")/"") * 1 + m.P(1)/".")^0), "aloal") == "a..a.") 518assert(m.match(m.Cs((-((-m.P"a")/"") * 1 + m.P(1)/".")^0), "aloal") == "a..a.")
527 519
528
529-- fixed length
530do
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)
546end
547
548
549p = -m.P'a' * m.Cc(1) + -m.P'b' * m.Cc(2) + -m.P'c' * m.Cc(3) 520p = -m.P'a' * m.Cc(1) + -m.P'b' * m.Cc(2) + -m.P'c' * m.Cc(3)
550assert(p:match('a') == 2 and p:match('') == 1 and p:match('b') == 1) 521assert(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)
1128end 1099end
1129 1100
1130
1131-- Return a match-time capture that returns 'n' captures
1132local 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)
1137end
1138
1139-- bug in 1.0: failed match-time that used previous match-time results
1140do
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)
1145end
1146
1147
1148-- bug in 1.0: problems with math-times returning too many captures
1149do
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")
1154end
1155
1156p = (m.P(function () return true, "a" end) * 'a' 1101p = (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