aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
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