Skip to content

Commit

Permalink
Add test for switch speed and duplicated case warning
Browse files Browse the repository at this point in the history
  • Loading branch information
XmiliaH authored and Sainan committed May 18, 2024
1 parent 47f521e commit a4172db
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions testes/pluto/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ end]]
assert_no_warn[[if false and true then
else
end]]

-- Duplicated case warning
assert_warn[[switch a do case 1: case 1: end]]
end

print "Testing assertion library."
Expand Down Expand Up @@ -1283,6 +1286,32 @@ do
end
assert(f() == nil)
end
-- Test switch speed
do
local N = 2000
local code = "return function(val)\nswitch val do"
for i=1, N do
code = code .. "\ncase " .. i .. ".5: return " .. i
end
code = code .. "\ndefault: return -1\nend\nend"
local f = load(code)()
-- Initialize, this might take more time
assert(f(0) == -1)
local function timeout()
debug.sethook()
assert(false)
end
local function test_with_timing(val)
debug.sethook(timeout, '', 40)
local ret = f(val)
debug.sethook()
return ret
end
for i=1, N do
assert(test_with_timing(i+0.5) == i)
end
assert(test_with_timing(0) == -1)
end

print "Testing table freezing."
do
Expand Down

0 comments on commit a4172db

Please sign in to comment.