aboutsummaryrefslogtreecommitdiff
path: root/test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test.lua')
-rwxr-xr-xtest.lua57
1 files changed, 56 insertions, 1 deletions
diff --git a/test.lua b/test.lua
index d5922ac..a3b86bf 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.109 2015/09/28 17:01:25 roberto Exp $ 3-- $Id: test.lua,v 1.112 2017/01/14 18:55:22 roberto Exp $
4 4
5-- require"strict" -- just to be pedantic 5-- require"strict" -- just to be pedantic
6 6
@@ -202,6 +202,14 @@ 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
205-- test for small capture boundary 213-- test for small capture boundary
206for i = 250,260 do 214for i = 250,260 do
207 assert(#m.match(m.C(i), string.rep('a', i)) == i) 215 assert(#m.match(m.C(i), string.rep('a', i)) == i)
@@ -517,6 +525,27 @@ assert(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.") 525assert(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.") 526assert(m.match(m.Cs((-((-m.P"a")/"") * 1 + m.P(1)/".")^0), "aloal") == "a..a.")
519 527
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
520p = -m.P'a' * m.Cc(1) + -m.P'b' * m.Cc(2) + -m.P'c' * m.Cc(3) 549p = -m.P'a' * m.Cc(1) + -m.P'b' * m.Cc(2) + -m.P'c' * m.Cc(3)
521assert(p:match('a') == 2 and p:match('') == 1 and p:match('b') == 1) 550assert(p:match('a') == 2 and p:match('') == 1 and p:match('b') == 1)
522 551
@@ -1098,6 +1127,32 @@ do
1098 assert(c == 11) 1127 assert(c == 11)
1099end 1128end
1100 1129
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
1101p = (m.P(function () return true, "a" end) * 'a' 1156p = (m.P(function () return true, "a" end) * 'a'
1102 + m.P(function (s, i) return i, "aa", 20 end) * 'b' 1157 + m.P(function (s, i) return i, "aa", 20 end) * 'b'
1103 + m.P(function (s,i) if i <= #s then return i, "aaa" end end) * 1)^0 1158 + m.P(function (s,i) if i <= #s then return i, "aaa" end end) * 1)^0