aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-24 14:01:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-24 14:01:20 -0300
commit3da34a5fa70a51f0cf06d677a4f07b470693260c (patch)
tree384aeb18a404a076a57188070f1e155a7cc24b3d /testes
parent20b161e2859837e4f7fb1c19440ad7efe1588f1f (diff)
downloadlua-3da34a5fa70a51f0cf06d677a4f07b470693260c.tar.gz
lua-3da34a5fa70a51f0cf06d677a4f07b470693260c.tar.bz2
lua-3da34a5fa70a51f0cf06d677a4f07b470693260c.zip
Revamp of 'lua_pushfstring' / 'luaO_pushvfstring'
The function 'luaO_pushvfstring' now uses an internal buffer to concatenate small strings, instead of pushing all pieces on the stack. This avoids the creation of several small Lua strings for each piece of the result. (For instance, a format like "n: '%d'" used to create three intermediate strings: "n: '", the numeral, and "'". Now it creates none.)
Diffstat (limited to 'testes')
-rw-r--r--testes/strings.lua61
1 files changed, 61 insertions, 0 deletions
diff --git a/testes/strings.lua b/testes/strings.lua
index 8bcbb391..66c1176d 100644
--- a/testes/strings.lua
+++ b/testes/strings.lua
@@ -400,5 +400,66 @@ do
400 assert(co() == "2") 400 assert(co() == "2")
401end 401end
402 402
403
404if T==nil then
405 (Message or print)
406 ("\n >>> testC not active: skipping 'pushfstring' tests <<<\n")
407else
408
409 print"testing 'pushfstring'"
410
411 -- formats %U, %f, %I already tested elsewhere
412
413 local blen = 400 -- internal buffer length in 'luaO_pushfstring'
414
415 local function callpfs (op, fmt, n)
416 local x = {T.testC("pushfstring" .. op .. "; return *", fmt, n)}
417 -- stack has code, 'fmt', 'n', and result from operation
418 assert(#x == 4) -- make sure nothing else was left in the stack
419 return x[4]
420 end
421
422 local function testpfs (op, fmt, n)
423 assert(callpfs(op, fmt, n) == string.format(fmt, n))
424 end
425
426 testpfs("I", "", 0)
427 testpfs("I", string.rep("a", blen - 1), 0)
428 testpfs("I", string.rep("a", blen), 0)
429 testpfs("I", string.rep("a", blen + 1), 0)
430
431 local str = string.rep("ab", blen) .. "%d" .. string.rep("d", blen / 2)
432 testpfs("I", str, 2^14)
433 testpfs("I", str, -2^15)
434
435 str = "%d" .. string.rep("cd", blen)
436 testpfs("I", str, 2^14)
437 testpfs("I", str, -2^15)
438
439 str = string.rep("c", blen - 2) .. "%d"
440 testpfs("I", str, 2^14)
441 testpfs("I", str, -2^15)
442
443 for l = 12, 14 do
444 local str1 = string.rep("a", l)
445 for i = 0, 500, 13 do
446 for j = 0, 500, 13 do
447 str = string.rep("a", i) .. "%s" .. string.rep("d", j)
448 testpfs("S", str, str1)
449 testpfs("S", str, str)
450 end
451 end
452 end
453
454 str = "abc %c def"
455 testpfs("I", str, string.byte("A"))
456 -- non-printable character
457 assert(callpfs("I", str, 255) == "abc <\\255> def")
458
459 str = string.rep("a", blen - 1) .. "%p" .. string.rep("cd", blen)
460 testpfs("P", str, {})
461end
462
463
403print('OK') 464print('OK')
404 465