tests: Expand conformance/basic with more arith checks

Check various specials that we can't optimize and division by large power of two.
This commit is contained in:
Arseny Kapoulkine 2024-11-26 21:26:46 +09:00
parent 434c8f2c42
commit fb56d8b0ec

View file

@ -92,6 +92,15 @@ assert((function() local a = 1 a = a - 2 return a end)() == -1)
assert((function() local a = 1 a = a * 2 return a end)() == 2)
assert((function() local a = 1 a = a / 2 return a end)() == 0.5)
-- binary ops with fp specials, neg zero, large constants
-- argument is passed into anonymous function to prevent constant folding
assert((function(a) return tostring(a + 0) end)(-0) == "0")
assert((function(a) return tostring(a - 0) end)(-0) == "-0")
assert((function(a) return tostring(a - a) end)(1 / 0) == "nan")
assert((function(a) return tostring(a * 0) end)(0 / 0) == "nan")
assert((function(a) return tostring(a / (2^1000)) end)(2^1000) == "1")
assert((function(a) return tostring(a / (2^-1000)) end)(2^-1000) == "1")
-- floor division should always round towards -Infinity
assert((function() local a = 1 a = a // 2 return a end)() == 0)
assert((function() local a = 3 a = a // 2 return a end)() == 1)
@ -290,7 +299,7 @@ assert((function() local t = {[1] = 1, [2] = 2} return t[1] + t[2] end)() == 3)
assert((function() return table.concat({}, ',') end)() == "")
assert((function() return table.concat({1}, ',') end)() == "1")
assert((function() return table.concat({1,2}, ',') end)() == "1,2")
assert((function() return table.concat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, ',') end)() ==
assert((function() return table.concat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, ',') end)() ==
"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15")
assert((function() return table.concat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, ',') end)() == "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16")
assert((function() return table.concat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}, ',') end)() == "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17")
@ -770,7 +779,7 @@ assert(tostring(0) == "0")
assert(tostring(-0) == "-0")
-- test newline handling in long strings
assert((function()
assert((function()
local s1 = [[
]]
local s2 = [[