github.com/hootrhino/gopher-lua@v1.0.3/_lua5.1-tests/verybig.lua (about)

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