aboutsummaryrefslogtreecommitdiff
path: root/test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test.lua')
-rwxr-xr-xtest.lua25
1 files changed, 22 insertions, 3 deletions
diff --git a/test.lua b/test.lua
index 8f9f574..f57cdec 100755
--- a/test.lua
+++ b/test.lua
@@ -406,7 +406,7 @@ assert(p:match('abcx') == 5 and p:match('ayzx') == 5 and not p:match'abc')
406 406
407 407
408do 408do
409 -- large dynamic Cc 409 print "testing large dynamic Cc"
410 local lim = 2^16 - 1 410 local lim = 2^16 - 1
411 local c = 0 411 local c = 0
412 local function seq (n) 412 local function seq (n)
@@ -985,10 +985,10 @@ for i = 1, 10 do
985 assert(p:match("aaaaaaaaaaa") == 11 - i + 1) 985 assert(p:match("aaaaaaaaaaa") == 11 - i + 1)
986end 986end
987 987
988print"+"
989 988
990 989
991-- tests for back references 990print "testing back references"
991
992checkerr("back reference 'x' not found", m.match, m.Cb('x'), '') 992checkerr("back reference 'x' not found", m.match, m.Cb('x'), '')
993checkerr("back reference 'b' not found", m.match, m.Cg(1, 'a') * m.Cb('b'), 'a') 993checkerr("back reference 'b' not found", m.match, m.Cg(1, 'a') * m.Cb('b'), 'a')
994 994
@@ -1171,9 +1171,28 @@ t = {p:match('abacc')}
1171checkeq(t, {'a', 'aa', 20, 'a', 'aaa', 'aaa'}) 1171checkeq(t, {'a', 'aa', 20, 'a', 'aaa', 'aaa'})
1172 1172
1173 1173
1174do print"testing large grammars"
1175 local lim = 1000 -- number of rules
1176 local t = {}
1177
1178 for i = 3, lim do
1179 t[i] = m.V(i - 1) -- each rule calls previous one
1180 end
1181 t[1] = m.V(lim) -- start on last rule
1182 t[2] = m.C("alo") -- final rule
1183
1184 local P = m.P(t) -- build grammar
1185 assert(P:match("alo") == "alo")
1186
1187 t[#t + 1] = m.P("x") -- one more rule...
1188 checkerr("too many rules", m.P, t)
1189end
1190
1191
1174------------------------------------------------------------------- 1192-------------------------------------------------------------------
1175-- Tests for 're' module 1193-- Tests for 're' module
1176------------------------------------------------------------------- 1194-------------------------------------------------------------------
1195print"testing 're' module"
1177 1196
1178local re = require "re" 1197local re = require "re"
1179 1198