@@ -115,10 +115,11 @@ local function f1 (s, p)
115115 return string.sub (s , t [1 ], t [# t ] - 1 )
116116end
117117
118- assert (f1 (' alo alx 123 b\0 o b\0 o' , ' (..*) %1' ) == " b\0 o b\0 o" )
119- assert (f1 (' axz123= 4= 4 34' , ' (.+)=(.*)=%2 %1' ) == ' 3= 4= 4 3' )
120- assert (f1 (' =======' , ' ^(=*)=%1$' ) == ' =======' )
121- assert (not string.match (' ==========' , ' ^([=]*)=%1$' ))
118+ -- XXX: Backreferences not supported.
119+ -- assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o")
120+ -- assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3')
121+ -- assert(f1('=======', '^(=*)=%1$') == '=======')
122+ -- assert(not string.match('==========', '^([=]*)=%1$'))
122123
123124local function range (i , j )
124125 if i <= j then
@@ -145,8 +146,9 @@ assert(strset('[^%W]') == strset('[%w]'))
145146assert (strset (' []%%]' ) == ' %]' )
146147assert (strset (' [a%-z]' ) == ' -az' )
147148assert (strset (' [%^%[%-a%]%-b]' ) == ' -[]^ab' )
148- assert (strset (' %Z' ) == strset (' [\1 -\255 ]' ))
149- assert (strset (' .' ) == strset (' [\1 -\255 %z]' ))
149+ -- XXX: Undocumented %z not supported.
150+ -- assert(strset('%Z') == strset('[\1-\255]'))
151+ assert (strset (' .' ) == strset (' [\0 -\255 ]' ))
150152print (' +' );
151153
152154assert (string.match (" alo xyzK" , " (%w+)K" ) == " xyz" )
@@ -227,13 +229,14 @@ local r = string.gsub(s, '()(%w+)()', function (a,w,b)
227229assert (s == r and t [1 ] == 1 and t [3 ] == 3 and t [7 ] == 4 and t [13 ] == 4 )
228230
229231
230- local function isbalanced (s )
231- return not string.find (string.gsub (s , " %b()" , " " ), " [()]" )
232- end
232+ -- XXX: Balances not supported.
233+ -- local function isbalanced (s)
234+ -- return not string.find(string.gsub(s, "%b()", ""), "[()]")
235+ -- end
233236
234- assert (isbalanced (" (9 ((8))(\0 ) 7) \0\0 a b ()(c)() a" ))
235- assert (not isbalanced (" (9 ((8) 7) a b (\0 c) a" ))
236- assert (string.gsub (" alo 'oi' alo" , " %b''" , ' "' ) == ' alo " alo' )
237+ -- assert(isbalanced("(9 ((8))(\0) 7) \0\0 a b ()(c)() a"))
238+ -- assert(not isbalanced("(9 ((8) 7) a b (\0 c) a"))
239+ -- assert(string.gsub("alo 'oi' alo", "%b''", '"') == 'alo " alo')
237240
238241
239242local t = {" apple" , " orange" , " lime" ; n = 0 }
@@ -252,8 +255,9 @@ assert(t[1] == "first" and t[2] == "second" and t[3] == undef)
252255checkerror (" invalid replacement value %(a table%)" ,
253256 string.gsub , " alo" , " ." , {a = {}})
254257checkerror (" invalid capture index %%2" , string.gsub , " alo" , " ." , " %2" )
255- checkerror (" invalid capture index %%0" , string.gsub , " alo" , " (%0)" , " a" )
256- checkerror (" invalid capture index %%1" , string.gsub , " alo" , " (%1)" , " a" )
258+ -- XXX: Backreferences not supported.
259+ -- checkerror("invalid capture index %%0", string.gsub, "alo", "(%0)", "a")
260+ -- checkerror("invalid capture index %%1", string.gsub, "alo", "(%1)", "a")
257261checkerror (" invalid use of '%%'" , string.gsub , " alo" , " ." , " %x" )
258262
259263
@@ -301,11 +305,12 @@ for w in string.gmatch("first second word", "%w+") do
301305end
302306assert (t [1 ] == " first" and t [2 ] == " second" and t [3 ] == " word" )
303307
304- t = {3 , 6 , 9 }
305- for i in string.gmatch (" xuxx uu ppar r" , " ()(.)%2" ) do
306- assert (i == table.remove (t , 1 ))
307- end
308- assert (# t == 0 )
308+ -- XXX: Backreferences not supported.
309+ -- t = {3, 6, 9}
310+ -- for i in string.gmatch ("xuxx uu ppar r", "()(.)%2") do
311+ -- assert(i == table.remove(t, 1))
312+ -- end
313+ -- assert(#t == 0)
309314
310315t = {}
311316for i ,j in string.gmatch (" 13 14 10 = 11, 15= 16, 22=23" , " (%d+)%s*=%s*(%d+)" ) do
@@ -355,12 +360,14 @@ assert(string.gsub("function", "%f[\1-\255]%w", ".") == ".unction")
355360assert (string.gsub (" function" , " %f[^\1 -\255 ]" , " ." ) == " function." )
356361
357362assert (string.find (" a" , " %f[a]" ) == 1 )
358- assert (string.find (" a" , " %f[^%z]" ) == 1 )
363+ -- XXX: Undocumented %z not supported.
364+ assert (string.find (" a" , " %f[^\0 ]" ) == 1 )
359365assert (string.find (" a" , " %f[^%l]" ) == 2 )
360- assert (string.find (" aba" , " %f[a%z]" ) == 3 )
361- assert (string.find (" aba" , " %f[%z]" ) == 4 )
362- assert (not string.find (" aba" , " %f[%l%z]" ))
363- assert (not string.find (" aba" , " %f[^%l%z]" ))
366+ -- XXX: Undocumented %z not supported.
367+ assert (string.find (" aba" , " %f[a\0 ]" ) == 3 )
368+ assert (string.find (" aba" , " %f[\0 ]" ) == 4 )
369+ assert (not string.find (" aba" , " %f[%l\0 ]" ))
370+ assert (not string.find (" aba" , " %f[^%l\0 ]" ))
364371
365372local i , e = string.find (" alo aalo allo" , " %f[%S].-%f[%s].-%f[%S]" )
366373assert (i == 2 and e == 5 )
@@ -388,8 +395,8 @@ malform("[]")
388395malform (" [^]" )
389396malform (" [a%]" )
390397malform (" [a%" )
391- malform (" %b" )
392- malform (" %ba" )
398+ malform (" %b" , " balances not supported " )
399+ malform (" %ba" , " balances not supported " )
393400malform (" %" )
394401malform (" %f" , " missing" )
395402
@@ -398,7 +405,8 @@ assert(string.match("ab\0\1\2c", "[\0-\2]+") == "\0\1\2")
398405assert (string.match (" ab\0\1\2 c" , " [\0 -\0 ]+" ) == " \0 " )
399406assert (string.find (" b$a" , " $\0 ?" ) == 2 )
400407assert (string.find (" abc\0 efg" , " %\0 " ) == 4 )
401- assert (string.match (" abc\0 efg\0\1 e\1 g" , " %b\0\1 " ) == " \0 efg\0\1 e\1 " )
408+ -- XXX: Balances not supported.
409+ -- assert(string.match("abc\0efg\0\1e\1g", "%b\0\1") == "\0efg\0\1e\1")
402410assert (string.match (" abc\0\0\0 " , " %\0 +" ) == " \0\0\0 " )
403411assert (string.match (" abc\0\0\0 " , " %\0 %\0 ?" ) == " \0\0 " )
404412
@@ -407,34 +415,35 @@ assert(string.find("abc\0\0","\0.") == 4)
407415assert (string.find (" abcx\0\0 abc\0 abc" ," x\0\0 abc\0 a." ) == 4 )
408416
409417
410- do -- test reuse of original string in gsub
411- local s = string.rep (" a" , 100 )
412- local r = string.gsub (s , " b" , " c" ) -- no match
413- assert (string.format (" %p" , s ) == string.format (" %p" , r ))
414-
415- r = string.gsub (s , " ." , {x = " y" }) -- no substitutions
416- assert (string.format (" %p" , s ) == string.format (" %p" , r ))
417-
418- local count = 0
419- r = string.gsub (s , " ." , function (x )
420- assert (x == " a" )
421- count = count + 1
422- return nil -- no substitution
423- end )
424- r = string.gsub (r , " ." , {b = ' x' }) -- "a" is not a key; no subst.
425- assert (count == 100 )
426- assert (string.format (" %p" , s ) == string.format (" %p" , r ))
427-
428- count = 0
429- r = string.gsub (s , " ." , function (x )
430- assert (x == " a" )
431- count = count + 1
432- return x -- substitution...
433- end )
434- assert (count == 100 )
435- -- no reuse in this case
436- assert (r == s and string.format (" %p" , s ) ~= string.format (" %p" , r ))
437- end
418+ -- XXX: Strings do not have a pointer address in our implementation.
419+ -- do -- test reuse of original string in gsub
420+ -- local s = string.rep("a", 100)
421+ -- local r = string.gsub(s, "b", "c") -- no match
422+ -- assert(string.format("%p", s) == string.format("%p", r))
423+
424+ -- r = string.gsub(s, ".", {x = "y"}) -- no substitutions
425+ -- assert(string.format("%p", s) == string.format("%p", r))
426+
427+ -- local count = 0
428+ -- r = string.gsub(s, ".", function (x)
429+ -- assert(x == "a")
430+ -- count = count + 1
431+ -- return nil -- no substitution
432+ -- end)
433+ -- r = string.gsub(r, ".", {b = 'x'}) -- "a" is not a key; no subst.
434+ -- assert(count == 100)
435+ -- assert(string.format("%p", s) == string.format("%p", r))
436+
437+ -- count = 0
438+ -- r = string.gsub(s, ".", function (x)
439+ -- assert(x == "a")
440+ -- count = count + 1
441+ -- return x -- substitution...
442+ -- end)
443+ -- assert(count == 100)
444+ -- -- no reuse in this case
445+ -- assert(r == s and string.format("%p", s) ~= string.format("%p", r))
446+ -- end
438447
439448print (' OK' )
440449
0 commit comments