aboutsummaryrefslogtreecommitdiff
path: root/testes/pm.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/pm.lua')
-rw-r--r--testes/pm.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/testes/pm.lua b/testes/pm.lua
index 8cc8772e..4d87fad2 100644
--- a/testes/pm.lua
+++ b/testes/pm.lua
@@ -387,5 +387,35 @@ assert(string.match("abc\0\0\0", "%\0%\0?") == "\0\0")
387assert(string.find("abc\0\0","\0.") == 4) 387assert(string.find("abc\0\0","\0.") == 4)
388assert(string.find("abcx\0\0abc\0abc","x\0\0abc\0a.") == 4) 388assert(string.find("abcx\0\0abc\0abc","x\0\0abc\0a.") == 4)
389 389
390
391do -- test reuse of original string in gsub
392 local s = string.rep("a", 100)
393 local r = string.gsub(s, "b", "c") -- no match
394 assert(string.format("%p", s) == string.format("%p", r))
395
396 r = string.gsub(s, ".", {x = "y"}) -- no substitutions
397 assert(string.format("%p", s) == string.format("%p", r))
398
399 local count = 0
400 r = string.gsub(s, ".", function (x)
401 assert(x == "a")
402 count = count + 1
403 return nil -- no substitution
404 end)
405 r = string.gsub(r, ".", {b = 'x'}) -- "a" is not a key; no subst.
406 assert(count == 100)
407 assert(string.format("%p", s) == string.format("%p", r))
408
409 count = 0
410 r = string.gsub(s, ".", function (x)
411 assert(x == "a")
412 count = count + 1
413 return x -- substitution...
414 end)
415 assert(count == 100)
416 -- no reuse in this case
417 assert(r == s and string.format("%p", s) ~= string.format("%p", r))
418end
419
390print('OK') 420print('OK')
391 421