1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

First test batch and associated fixes

The test runner is also nicer to use.
This commit is contained in:
Étienne Fildadut 2023-12-28 16:51:18 +01:00
parent 10084dec23
commit 82ce53be83
154 changed files with 1586 additions and 78 deletions

View file

@ -0,0 +1,11 @@
--# run #--
--- text ---
| {}"" {}"-3" {}""|
--- text ---
| {}"" {}"heh minus lol" {}""|
--- text ---
| {}"" {}"generic minus" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"" {}"1" {}""|
--- text ---
| {}"" {}"3" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,15 @@
--# run #--
--- choice ---
> | {}"ye "|
=> | {}"ne "|
--- text ---
| {}"ok"|
--- choice ---
=> | {}"ho "|
> | {}"oh "|
--- text ---
| {}"plop"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,12 @@
--# run #--
--- choice ---
> | {}"ho "|
> | {}"neol "|
=> | {}"oh "|
> | {}"neol "|
--- text ---
| {}"ok"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,11 @@
--# run #--
--- text ---
| {1:1}"A"|
--- choice ---
=> | {}"Suprise choice! "|
> | {}"Press " {}"JOIN" {}" to jump. "|
> | {}"No "|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,12 @@
--# run #--
--- text ---
| {1:1}"a"|
--- choice ---
=> | {}"Press " {}"SPLIT" {}" to jump. "|
> | {}"No "|
--- text ---
| {}"ok"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,19 @@
--# run #--
--- choice ---
=> | {}"Press " {1:1}"A" {}" to jump. "|
> | {}"No "|
--- text ---
| {}"ok"|
--- choice ---
=> | {}"Other "|
--- text ---
| {}"ok"|
| {1:1}"left"|
--- choice ---
=> | {}"Use " {}" joystick" {}" to move. "|
--- text ---
| {}"ko"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,18 @@
--# run #--
--- choice ---
=> | {1:42}"a "|
> | {}"c "|
--- text ---
| {1:42}"b"|
--- choice ---
=> | {1:42}"a "|
> | {"k":"v"}"d "|
--- text ---
| {1:42}"b"|
| {"k":"v"}"e"|
--- text ---
| {}"f"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,10 @@
--# run #--
--- choice ---
> | {}"ye "|
=> | {}"ne "|
--- text ---
| {}"ok"|
--- return ---
()
--# saved #--
{}

11
test/results/closure.ans Normal file
View file

@ -0,0 +1,11 @@
--# run #--
--- text ---
| {}"" {}"5" {}" = 5"|
| {}"" {}"8" {}" = 8"|
--- text ---
| {}"" {}"4" {}" = 4"|
| {}"" {}"7" {}" = 7"|
--- return ---
()
--# saved #--
{}

5
test/results/comment.ans Normal file
View file

@ -0,0 +1,5 @@
--# run #--
--- return ---
8
--# saved #--
{}

View file

@ -0,0 +1,8 @@
--# run #--
--- text ---
| {}"ok"|
| {}"ok bis"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"ok"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"ok"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"ok"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"ok"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,5 @@
--# run #--
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"a " {}"b" {}" c"|
--- text ---
| {}"a " {}"()" {}" c"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"ok"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- error ---
./state/State.lua:145: trying to change the value of constant a
↳ from test/tests/constant variable.ans:5:3 in assignment: a = 52
↳ from ? in block: ::a = 3…
--# saved #--
{}

View file

@ -0,0 +1,8 @@
--# run #--
--- text ---
| {}"" {}"\"Name: Darmanin\\\
Age: 38\"" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,4 @@
--# parse error #--
a is already defined in the current scope
↳ from test/tests/define override function.ans:4:4 in definition: :a = 2
↳ from ? in block: :a = ($() _)…

View file

@ -0,0 +1,5 @@
--# parse error #--
can't add an overload variant to non-overloadable variable a defined in the same scope
↳ from test/tests/define override variable.ans:3:1 in definition: :a = ($() _)
↳ from test/tests/define override variable.ans:3:1 in attach block: :a = ($() _)…
↳ from ? in block: :a = 2…

View file

@ -0,0 +1,4 @@
--# parse error #--
a is already defined in the current scope
↳ from test/tests/define override.ans:3:4 in definition: :a = 2
↳ from ? in block: :a = 5…

5
test/results/define.ans Normal file
View file

@ -0,0 +1,5 @@
--# run #--
--- return ---
()
--# saved #--
{}

13
test/results/flush.ans Normal file
View file

@ -0,0 +1,13 @@
--# run #--
--- text ---
| {}"a"|
--- choice ---
=> | {}"b "|
--- text ---
| {}"c"|
--- choice ---
=> | {}"d "|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"ok" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- error ---
./state/State.lua:145: can't call closure ($(a, b) _): expected 2 arguments, received 1
↳ from test/tests/function args arity check fail.ans:4:2 in call: f("ok")
↳ from ? in block: :f = ($(a, b) _)…
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"o" {}"" {}"k" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,15 @@
--# run #--
--- text ---
| {}"" {}"5" {}""|
--- text ---
| {}"v=" {}"50" {}""|
--- text ---
| {}"" {}"50" {}""|
--- text ---
| {}"v2=" {}"ok" {}""|
--- text ---
| {}"" {}"3" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,15 @@
--# run #--
--- text ---
| {}"" {}"25" {}" = " {}"25" {}""|
--- text ---
| {}"" {}"4" {}" = " {}"4" {}""|
--- text ---
| {}"" {}"14" {}" == 14"|
--- text ---
| {}"" {}"32" {}" == 32"|
--- text ---
| {}"" {}"49" {}" == 49"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"a"|
--- text ---
| {}"x"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,5 @@
--# run #--
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"5" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"5" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- error ---
./state/State.lua:145: identifier "b" is undefined in branch 0a138a38-3faa-4478-10f6f-1a9de1e0a8e1
↳ from test/tests/function scope wrong.ans:4:7 in identifier: b
↳ from test/tests/function scope wrong.ans:4:1 in text interpolation: | a: {b}|
↳ from test/tests/function scope wrong.ans:4:1 in translatable: | a: {b}|
↳ from ? in block: :a = ($() _)…
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"a: " {}"5" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"" {}"plopheh" {}""|
--- text ---
| {}"" {}"4" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- error ---
./state/State.lua:145: can't call overload overload<($(a::($(x) <lua function>)) _), ($(x::($(x) <lua function>)) _)>: more than one function match (5), matching functions were at least (specificity 1.3):
• (x::($(x) <lua function>))
• (a::($(x) <lua function>))
↳ from test/tests/function type dispatch ambigous.ans:7:3 in call: fn(5)
↳ from ? in block: :fn = ($(x::number) _)…
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"a"|
--- text ---
| {}"x"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"" {}"ok" {}""|
--- text ---
| {}"" {}"ok" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"o" {}"" {}"k" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"ok"|
--- text ---
| {}"ok2"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,15 @@
--# run #--
--- text ---
| {}"" {}"8" {}" = 8"|
--- text ---
| {}"" {}"12" {}" = 12"|
--- text ---
| {}"" {}"6.28" {}" = 2pi"|
--- text ---
| {}"" {}"0.125" {}" = 0.125"|
--- text ---
| {}"" {}"2.1" {}" = 2.1"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,33 @@
--# run #--
--- text ---
| {}"a"|
| {}"b"|
| {}"" {}"()" {}" = a b ()"|
--- text ---
| {}"b"|
| {}"" {}"()" {}" = b ()"|
--- text ---
| {}"a"|
| {}"a"|
| {}"" {}"1" {}" = a a 1"|
--- text ---
| {}"b"|
| {}"" {}"()" {}" = b ()"|
--- text ---
| {}"a"|
| {}"" {}"1" {}" = a 1"|
--- text ---
| {}"b"|
| {}"a"|
| {}"" {}"1" {}" = b a 1"|
--- text ---
| {}"a"|
| {}"" {}"1" {}" = a 1"|
--- text ---
| {}"b"|
| {}"b"|
| {}"" {}"()" {}" = b b ()"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,17 @@
--# run #--
--- text ---
| {}"" {}"*[1, 2]" {}""|
--- text ---
| {}"" {}"*[3, 2]" {}""|
--- text ---
| {}"" {}"*[3, 5]" {}""|
--- text ---
| {}"" {}"*[3, 12]" {}""|
--- text ---
| {}"" {}"*[3, 12, 99]" {}""|
--- error ---
./state/State.lua:145: list index out of bounds
↳ from test/tests/list assignement.ans:21:6 in call: x(5) = 0
↳ from ? in block: :x = *[1, 2]…
--# saved #--
{}

View file

@ -0,0 +1,17 @@
--# run #--
--- text ---
| {}"" {}"[1, 2, 3]" {}""|
--- text ---
| {}"" {}"1" {}" == " {}"1" {}""|
--- text ---
| {}"" {}"2" {}" == " {}"2" {}""|
--- text ---
| {}"" {}"3" {}" == " {}"3" {}""|
--- error ---
./state/State.lua:145: tuple index out of bounds
↳ from test/tests/list index.ans:11:4 in call: x(-4)
↳ from test/tests/list index.ans:11:1 in text interpolation: | {x(-4)}|
↳ from test/tests/list index.ans:11:1 in translatable: | {x(-4)}|
↳ from ? in block: :x = [1, 2, 3]…
--# saved #--
{}

View file

@ -0,0 +1,28 @@
--# run #--
--- text ---
| {}"" {}"1" {}"" {}"\
" {}""|
| {}"" {}"2" {}"" {}"\
" {}""|
| {}"" {}"3" {}"" {}"\
" {}""|
| {}"" {}"4" {}"" {}"\
" {}""|
| {}"" {}"5" {}"" {}"\
" {}""|
| {}"" {}"6" {}"" {}"\
" {}""|
| {}"" {}"7" {}"" {}"\
" {}""|
| {}"" {}"8" {}"" {}"\
" {}""|
| {}"" {}"9" {}"" {}"\
" {}""|
| {}"" {}"10" {}"" {}"\
" {}""|
--- text ---
| {}"" {}"11" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,23 @@
--# run #--
--- text ---
| {}"" {}"*{1:1, 2:2}" {}""|
--- text ---
| {}"" {}"()" {}""|
--- text ---
| {}"" {}"*{1:3, 2:2}" {}""|
--- text ---
| {}"" {}"()" {}""|
--- text ---
| {}"" {}"*{\"foo\":\"a\", 1:3, 2:2}" {}""|
--- text ---
| {}"" {}"()" {}""|
--- text ---
| {}"" {}"*{\"bar\":\"b\", \"foo\":\"a\", 1:3, 2:2}" {}""|
--- text ---
| {}"" {}"()" {}""|
--- text ---
| {}"" {}"*{\"bar\":\"b\", \"foo\":\"c\", 1:3, 2:2}" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,11 @@
--# run #--
--- text ---
| {}"" {}"{\"ahah\":23, \"k\":23, 3:12}" {}" == " {}"{" {}"3=12, ahah=23, k=23}"|
--- text ---
| {}"" {}"12" {}" == 12"|
--- text ---
| {}"" {}"23" {}" == 23"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"abc" {}" = " {}"abc" {}" = " {}"abc" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"5" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,10 @@
--# run #--
--- text ---
| {}"yes"|
--- text ---
| {}"ye"|
| {}"da"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,20 @@
--# run #--
--- text ---
| {}"a"|
--- text ---
| {}"b"|
--- text ---
| {}"c"|
| {}"d"|
--- text ---
| {}"e"|
--- choice ---
=> | {}"f "|
--- text ---
| {}"g"|
--- choice ---
=> | {}"h "|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"abc" {}" = " {}"abc" {}" = " {}"abc" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"" {}"[\"test\":1, 3:\"p\", \"test\":\"foo\", \"ho\":\"ah\", \"test\":\"test\"]" {}""|
--- text ---
| {}"" {}"[\"name\":1, 3:\"p\", \"test\":\"foo\", \"ho\":\"ah\", \"name\":\"test\"]" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,10 @@
--# run #--
--- choice ---
=> | {}"a "|
--- text ---
| {}"x"|
| {}"Yes."|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,14 @@
--# run #--
--- text ---
| {}"expression " {}"a" {}""|
--- text ---
| {}"quote " {}"\"" {}""|
--- text ---
| {}"other codes " {}"\
" {}" " {}"\\" {}" " {}"\9" {}" " {}"{" {}"braces}"|
--- text ---
| {}"" {}"escaping expressions abc and {stuff} \\ and quotes \"" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,8 @@
--# run #--
--- text ---
| {1:1}"foo"|
| {"a":[2, 3], "b":[1, 2], 1:1}"bar"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,8 @@
--# run #--
--- text ---
| {1:1}"foo"|
| {"a":[2, 3], 1:1}"bar"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,8 @@
--# run #--
--- text ---
| {1:1}"foo"|
| {1:1}"bar"|
--- return ---
()
--# saved #--
{}

8
test/results/tag.ans Normal file
View file

@ -0,0 +1,8 @@
--# run #--
--- text ---
| {1:1}"foo"|
| {"a":[2, 3], 1:1}"bar"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,11 @@
--# run #--
--- text ---
| {}"a"|
| {}"b c"|
--- text ---
| {}"a"|
| {}"b c"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"a"|
--- text ---
| {}"b c"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,16 @@
--# run #--
--- text ---
| {}"expression " {}"{" {}"a}"|
--- text ---
| {}"quote " {}"\"" {}""|
--- text ---
| {}"other codes " {}"\
" {}" " {}"\\" {}" " {}"\9" {}""|
--- text ---
| {}"decorators " {}"#" {}" tag " {}"~" {}" condition " {}"$" {}" fn"|
--- text ---
| {}"sub " {}"[" {}"text]"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"a: " {}"5" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,19 @@
--# run #--
--- text ---
| {1:1}"A"|
--- choice ---
=> | {}"Surprise choice! "|
--- text ---
| {}"ok"|
| {}"Press " {}"()" {}" to jump."|
--- text ---
| {1:1}"left"|
--- choice ---
=> | {}"Surprise choice! "|
--- text ---
| {}"ok2"|
| {}"Use " {}" joystick" {}" to move."|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,13 @@
--# run #--
--- text ---
| {1:1}"A"|
--- text ---
| {}"Press " {}"()" {}" to jump."|
--- text ---
| {1:1}"left"|
--- text ---
| {}"Use " {}" joystick" {}" to move."|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,10 @@
--# run #--
--- text ---
| {}"Press " {1:1}"A" {}" to jump."|
--- text ---
| {1:2}"left"|
| {}"Use " {}" joystick" {}" to move."|
--- return ---
()
--# saved #--
{}

7
test/results/text.ans Normal file
View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"a"|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,11 @@
--# run #--
--- text ---
| {}"" {}"-5" {}""|
--- text ---
| {}"" {}"minus lol" {}""|
--- text ---
| {}"" {}"generic minus" {}""|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,19 @@
--# run #--
--- text ---
| {}"Start with i=" {}"1" {}":"|
--- text ---
| {}"" {}"1" {}""|
--- text ---
| {}"" {}"2" {}""|
--- text ---
| {}"" {}"3" {}""|
--- text ---
| {}"" {}"4" {}""|
--- text ---
| {}"Start with i=" {}"5" {}":"|
--- text ---
| {}"Loop not ran."|
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,41 @@
--# run #--
--- text ---
| {}"" {}"0" {}""|
--- text ---
| {}"" {}"1" {}""|
--- text ---
| {}"" {}"2" {}""|
--- text ---
| {}"" {}"3" {}""|
--- text ---
| {}"" {}"4" {}""|
--- text ---
| {}"" {}"5" {}""|
--- text ---
| {}"" {}"6" {}""|
--- text ---
| {}"" {}"7" {}""|
--- text ---
| {}"" {}"8" {}""|
--- text ---
| {}"" {}"9" {}""|
--- text ---
| {}"" {}"10" {}""|
--- text ---
| {}"return in loop:"|
--- text ---
| {}"" {}"0" {}""|
--- text ---
| {}"" {}"1" {}""|
--- text ---
| {}"" {}"2" {}""|
--- text ---
| {}"" {}"3" {}""|
--- text ---
| {}"" {}"4" {}""|
--- text ---
| {}"" {}"5" {}""|
--- return ---
@()
--# saved #--
{}

View file

@ -1,8 +1,27 @@
-- Require LuaFileSystem: luarocks install luafilesystem
local lfs = require("lfs")
local anselme = require("anselme")
local persistent_manager = require("state.persistent_manager")
-- simple random to get the same result across lua versions
local prev = 0
local function badrandom(a, b)
prev = (4241 * prev + 11) % 6997
return a + prev % (b-a+1)
end
function math.random(a, b)
if not a and not b then
return badrandom(0, 999) / 1000
elseif not b then
return badrandom(1, a)
else
return badrandom(a, b)
end
end
-- run a test file and return the result
local function run(path)
local state = anselme:new()
state:load_stdlib()
@ -10,9 +29,13 @@ local function run(path)
local run_state = state:branch()
local f = assert(io.open(path, "r"))
local block = anselme.parse(f:read("*a"), path)
local s, block = pcall(anselme.parse, f:read("*a"), path)
f:close()
if not s then
return "--# parse error #--\n"..tostring(block)
end
run_state:run(block)
local out = { "--# run #--" }
@ -48,6 +71,29 @@ local function run(path)
return table.concat(out, "\n")
end
-- display an animated loading indicator
io.stdout:setvbuf("no")
local loading = {
loop = { "", "", "", "", "", "", "", "" },
loop_pos = 1,
erase_code = "",
write = function(self, message)
self:clear()
local str = self.loop[self.loop_pos].." "..message
self.erase_code = ("\b"):rep(#str)
io.write(str)
end,
clear = function(self)
io.write(self.erase_code)
end,
update = function(self)
self.loop_pos = self.loop_pos + 1
if self.loop_pos > #self.loop then self.loop_pos = 1 end
end
}
-- list tests
local tests = {}
for test in lfs.dir("test/tests/") do
if test:match("%.ans$") then
@ -55,89 +101,85 @@ for test in lfs.dir("test/tests/") do
end
end
if arg[1] == "help" then
print("usage:")
print("lua test/run.lua: run all the tests")
print("lua test/run.lua write: write missing result files")
print("lua test/run.lua help: display this message")
elseif arg[1] == "write" then
for _, test in ipairs(tests) do
local f = io.open(test:gsub("^test/tests/", "test/results/"), "r")
if f then
f:close()
else
repeat
local rerun = false
-- run!
if not arg[1] or arg[1] == "update" then
local total, failure, errored, notfound = #tests, 0, 0, 0
for i, test in ipairs(tests) do
repeat
local rerun = false
-- load result
local f = io.open(test:gsub("^test/tests/", "test/results/"), "r")
local expected
if f then
expected = f:read("*a")
f:close()
end
-- run test
local result = run(test)
if result ~= expected then
loading:clear()
print("* "..test)
local c = assert(io.open(test, "r"))
local code = c:read("*a")
c:close()
print(" Code:")
print(" "..code:gsub("\n", "\n "))
local s, result = pcall(run, test)
if not s then
print(" Unexpected error: "..tostring(result))
local r
repeat
io.write("Edit this file? (y/N) ")
r = io.read("*l"):lower()
until r == "y" or r == "n" or r == ""
if r == "y" then
os.execute(("micro %q"):format(test)) -- hardcoded but oh well
rerun = true
end
if expected then failure = failure + 1
else notfound = notfound + 1
end
if arg[1] == "update" then
local c = assert(io.open(test, "r"))
local code = c:read("*a")
c:close()
print(" Code:")
print(" "..code:gsub("\n", "\n "))
end
if expected then
print(" Expected result: \n "..expected:gsub("\n", "\n "))
print(" But received: \n "..result:gsub("\n", "\n "))
else
print(" Result:")
print(" "..result:gsub("\n", "\n "))
print(" No result file found, generated result: \n "..result:gsub("\n", "\n "))
end
if arg[1] == "update" then
local r
repeat
io.write("Write this result? (y/N/e) ")
if expected then
io.write("Update this result? (y/N/e) ")
else
io.write("Write this result? (y/N/e) ")
end
r = io.read("*l"):lower()
until r == "y" or r == "n" or r == "e" or r == ""
if r == "y" then
local o = assert(io.open(test:gsub("^test/tests/", "test/results/"), "w"))
o:write(result)
o:close()
if expected then failure = failure - 1
else notfound = notfound - 1
end
elseif r == "e" then
os.execute(("micro %q"):format(test)) -- hardcoded but oh well
rerun = true
if expected then failure = failure - 1
else notfound = notfound - 1
end
end
end
until not rerun
end
end
elseif not arg[1] then
local total, failure, errored, notfound = #tests, 0, 0, 0
for _, test in ipairs(tests) do
local f = io.open(test:gsub("^test/tests/", "test/results/"), "r")
if f then
local s, result = pcall(run, test)
if not s then
errored = errored + 1
print("* "..test)
print(" Unexpected error: "..tostring(result))
else
local expected = f:read("*a")
if result ~= expected then
failure = failure + 1
print("* "..test)
print(" Expected: \n "..expected:gsub("\n", "\n "))
print(" But received: \n "..result:gsub("\n", "\n "))
print("")
end
print("")
end
f:close()
else
notfound = notfound + 1
print("* "..test)
print(" Result file not found.")
print("")
end
until not rerun
-- status
loading:write(("%s/%s tests ran"):format(i, #tests))
if i % 10 == 0 then loading:update() end
end
loading:clear()
print("#### Results ####")
print(("%s successes, %s failures, %s errors, %s missing result files, out of %s tests"):format(total-failure-notfound-errored, failure, errored, notfound, total))
local successes = total-failure-notfound-errored
print(("%s successes, %s failures, %s errors, %s missing result files, out of %s tests"):format(successes, failure, errored, notfound, total))
if successes < total then os.exit(1) end
else
print("unknown command, run `lua test/run.lua help` for usage")
print("usage:")
print("lua test/run.lua: run all the tests")
print("lua test/run.lua update: run all tests, optionally updating incorrect or missing results")
print("lua test/run.lua help: display this message")
end

View file

@ -0,0 +1,11 @@
:$ a - b
@"generic minus"
:$ a::string - b::string
@a + " minus " + b
| {2-5}
| {"heh"-"lol"}
| {[]-[]}

View file

@ -0,0 +1,7 @@
:c = 1
|{c}
c += 2
|{c}

View file

@ -0,0 +1,11 @@
:@choice = 2
| ye |>
| no
| ne |>
| ok
choice = 1
| ho |>
| plop
| oh |>
| plup

View file

@ -0,0 +1,11 @@
:$ f
| neol |>
| nah
| ho |>
|plop
f!
| oh |>
|ok
f!
:@choice=3

View file

@ -0,0 +1,11 @@
:@choice=1
:$ jump button
1 # |A
| Suprise choice! |> ()
@"JOIN"
| Press {jump button!} to jump. |>
|ok
| No |>
|ko

View file

@ -0,0 +1,11 @@
:@choice=1
:$ jump button
1 # | a
@"SPLIT"
| Press {jump button!} to jump. |>
| ok
| No |>
| ko

View file

@ -0,0 +1,17 @@
:$ jump button
@1 # | A
:$ move axis
1 # | left
@" joystick"
| Press {jump button!} to jump. |>
|ok
| No |>
|ko
:@choice = 1
| Other |>
|ok
| Use {move axis!} to move. |>
|ko

View file

@ -0,0 +1,16 @@
:choice = 1
:$ f
42 #
| a |>
| b
f!
| c |> ()
"k":"v" #
f!
| d |> ()
| e
| f

View file

@ -0,0 +1,5 @@
| ye |>
| no
| ne |>
| ok
:@choice = 2

12
test/tests/closure.ans Normal file
View file

@ -0,0 +1,12 @@
:$ f(x)
$(y) x + y
:add two = f(2)
:add five = f(5)
|{add two(3)} = 5
|{add five(3)} = 8
|{add two(2)} = 4
|{add five(2)} = 7

9
test/tests/comment.ans Normal file
View file

@ -0,0 +1,9 @@
((hey couic + 5))
((nested ((comments)) d))
2 ((end of line))
((start of line)) 3
5 + ((middle)) 3

View file

@ -0,0 +1,3 @@
() ~ |ko
1 ~ |ok
1 ~ |ok bis

View file

@ -0,0 +1,6 @@
:a = 5
a == 2 ~
|ko
~
|ok

View file

@ -0,0 +1,6 @@
:a = 5
a == 5 ~
|ok
~
|ko

View file

@ -0,0 +1,8 @@
:a = 5
a == 2 ~
|ko
~ () ~
|ko
~
|ok

View file

@ -0,0 +1,8 @@
:a = 5
a == 2 ~
|ko
~ 1 ~
|ok
~
|ko

View file

@ -0,0 +1,4 @@
:a = 5
a == 2 ~
|ko

View file

@ -0,0 +1,6 @@
:$ f
@|b
|a {5 ~ f!} c
|a {() ~ f!} c

View file

@ -0,0 +1,4 @@
:a = 5
a == 5 ~
|ok

View file

@ -0,0 +1,7 @@
::a = 3
{a}
a = 52
{a}

View file

@ -0,0 +1,12 @@
:person = "personne"
:$ format(p::is(person))
p = p!value
@"Name: {p("name")}\nAge: {p("age")}"
:$ Person(name, age)
@{"name":name, "age":age}!type(person)
:abject = Person("Darmanin", 38)
|{abject}

View file

@ -0,0 +1,4 @@
:$ a
()
:a = 2

View file

@ -0,0 +1,4 @@
:a = 2
:$ a
()

View file

@ -0,0 +1,5 @@
:a = 5
:a = 2
a: {a}

1
test/tests/define.ans Normal file
View file

@ -0,0 +1 @@
:a = 5

7
test/tests/flush.ans Normal file
View file

@ -0,0 +1,7 @@
:@choice = 1
| a
| b |> ()
| c
| d |> ()

Some files were not shown because too many files have changed in this diff Show more