verybig.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. if rawget(_G, "_soft") then return 10 end
  2. print "testing large programs (>64k)"
  3. -- template to create a very big test file
  4. prog = [[$
  5. local a,b
  6. b = {$1$
  7. b30009 = 65534,
  8. b30010 = 65535,
  9. b30011 = 65536,
  10. b30012 = 65537,
  11. b30013 = 16777214,
  12. b30014 = 16777215,
  13. b30015 = 16777216,
  14. b30016 = 16777217,
  15. b30017 = 4294967294,
  16. b30018 = 4294967295,
  17. b30019 = 4294967296,
  18. b30020 = 4294967297,
  19. b30021 = -65534,
  20. b30022 = -65535,
  21. b30023 = -65536,
  22. b30024 = -4294967297,
  23. b30025 = 15012.5,
  24. $2$
  25. };
  26. assert(b.a50008 == 25004 and b["a11"] == 5.5)
  27. assert(b.a33007 == 16503.5 and b.a50009 == 25004.5)
  28. assert(b["b"..30024] == -4294967297)
  29. function b:xxx (a,b) return a+b end
  30. assert(b:xxx(10, 12) == 22) -- pushself with non-constant index
  31. b.xxx = nil
  32. s = 0; n=0
  33. for a,b in pairs(b) do s=s+b; n=n+1 end
  34. assert(s==13977183656.5 and n==70001)
  35. require "checktable"
  36. stat(b)
  37. a = nil; b = nil
  38. print'+'
  39. function f(x) b=x end
  40. a = f{$3$} or 10
  41. assert(a==10)
  42. assert(b[1] == "a10" and b[2] == 5 and b[table.getn(b)-1] == "a50009")
  43. function xxxx (x) return b[x] end
  44. assert(xxxx(3) == "a11")
  45. a = nil; b=nil
  46. xxxx = nil
  47. return 10
  48. ]]
  49. -- functions to fill in the $n$
  50. F = {
  51. function () -- $1$
  52. for i=10,50009 do
  53. io.write('a', i, ' = ', 5+((i-10)/2), ',\n')
  54. end
  55. end,
  56. function () -- $2$
  57. for i=30026,50009 do
  58. io.write('b', i, ' = ', 15013+((i-30026)/2), ',\n')
  59. end
  60. end,
  61. function () -- $3$
  62. for i=10,50009 do
  63. io.write('"a', i, '", ', 5+((i-10)/2), ',\n')
  64. end
  65. end,
  66. }
  67. file = os.tmpname()
  68. io.output(file)
  69. for s in string.gmatch(prog, "$([^$]+)") do
  70. local n = tonumber(s)
  71. if not n then io.write(s) else F[n]() end
  72. end
  73. io.close()
  74. result = dofile(file)
  75. assert(os.remove(file))
  76. print'OK'
  77. return result