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:
parent
10084dec23
commit
82ce53be83
154 changed files with 1586 additions and 78 deletions
|
|
@ -23,7 +23,9 @@ local VariableMetadata = ast.abstract.Runtime {
|
|||
end
|
||||
end,
|
||||
set = function(self, state, value)
|
||||
assert(not self.symbol.constant, ("trying to change the value of constant %s"):format(self.symbol.string))
|
||||
if self.symbol.constant then
|
||||
error(("trying to change the value of constant %s"):format(self.symbol.string), 0)
|
||||
end
|
||||
if self.symbol.type_check then
|
||||
local r = self.symbol.type_check:call(state, ArgumentTuple:new(value))
|
||||
if not r:truthy() then error(("type check failure for %s; %s does not satisfy %s"):format(self.symbol.string, value, self.symbol.type_check)) end
|
||||
|
|
@ -82,7 +84,7 @@ local Environment = ast.abstract.Runtime {
|
|||
define = function(self, state, symbol, exp)
|
||||
local name = symbol.string
|
||||
if self:defined_in_current(state, symbol) then
|
||||
error(name.." is already defined in the current scope")
|
||||
error(name.." is already defined in the current scope", 0)
|
||||
end
|
||||
if (self.partial and not self.partial[name])
|
||||
or (self.export ~= symbol.exported) then
|
||||
|
|
@ -107,7 +109,7 @@ local Environment = ast.abstract.Runtime {
|
|||
elseif Overloadable:issub(val) then
|
||||
exp = Overload:new(exp, val)
|
||||
elseif self:defined_in_current(state, symbol) then
|
||||
error(("can't add an overload variant to non-overloadable variable %s defined in the same scope"):format(identifier))
|
||||
error(("can't add an overload variant to non-overloadable variable %s defined in the same scope"):format(identifier), 0)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ List = ast.abstract.Runtime {
|
|||
get = function(self, state, index)
|
||||
local list = self.branched:get(state)
|
||||
if index < 0 then index = #list.list + 1 + index end
|
||||
if index > #list.list or index == 0 then error("list index out of bounds") end
|
||||
if index > #list.list or index == 0 then error("list index out of bounds", 0) end
|
||||
return list.list[index]
|
||||
end,
|
||||
set = function(self, state, index, val)
|
||||
local list = self:_prepare_branch(state)
|
||||
if index < 0 then index = #list.list + 1 + index end
|
||||
if index > #list.list or index == 0 then error("list index out of bounds") end
|
||||
if index > #list.list+1 or index == 0 then error("list index out of bounds", 0) end
|
||||
list.list[index] = val
|
||||
end,
|
||||
insert = function(self, state, val)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ local TupleToStruct = ast.abstract.Node {
|
|||
|
||||
_eval = function(self, state)
|
||||
local t = Struct:new()
|
||||
for i, e in ipairs(self.tuple.list) do
|
||||
local tuple = self.tuple:eval(state)
|
||||
for i, e in ipairs(tuple.list) do
|
||||
if Pair:is(e) then
|
||||
t:set(e.name, e.value)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ Tuple = ast.abstract.Node {
|
|||
|
||||
get = function(self, index)
|
||||
if index < 0 then index = #self.list + 1 + index end
|
||||
if index > #self.list or index == 0 then error("tuple index out of bounds") end
|
||||
if index > #self.list or index == 0 then error("tuple index out of bounds", 0) end
|
||||
return self.list[index]
|
||||
end
|
||||
}
|
||||
|
|
|
|||
21
run tests.sh
Executable file
21
run tests.sh
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Run the test suite accross supported Lua versions.
|
||||
# Note that the test suite require luafilesystem: `luarocks --lua-version=5.4 install luafilesystem`
|
||||
|
||||
echo "/----------------------------\\"
|
||||
echo "| Running tests with Lua 5.4 |"
|
||||
echo "\\----------------------------/"
|
||||
lua5.4 test/run.lua
|
||||
echo ""
|
||||
|
||||
echo "/----------------------------\\"
|
||||
echo "| Running tests with Lua 5.3 |"
|
||||
echo "\\----------------------------/"
|
||||
lua5.3 test/run.lua
|
||||
echo ""
|
||||
|
||||
echo "/---------------------------\\"
|
||||
echo "| Running tests with LuaJIT |"
|
||||
echo "\\---------------------------/"
|
||||
luajit test/run.lua
|
||||
|
|
@ -21,9 +21,8 @@ return {
|
|||
"_~_", "(condition, expression)", function(state, condition, expression)
|
||||
ensure_if_variable(state)
|
||||
if condition:truthy() then
|
||||
local r = expression:call(state, ArgumentTuple:new())
|
||||
set_if_variable(state, true)
|
||||
return r
|
||||
return expression:call(state, ArgumentTuple:new())
|
||||
else
|
||||
set_if_variable(state, false)
|
||||
return Nil:new()
|
||||
|
|
@ -37,9 +36,8 @@ return {
|
|||
if last_if_success(state) then
|
||||
return Nil:new()
|
||||
else
|
||||
local r = expression:call(state, ArgumentTuple:new())
|
||||
set_if_variable(state, true)
|
||||
return r
|
||||
return expression:call(state, ArgumentTuple:new())
|
||||
end
|
||||
end
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
local ast = require("ast")
|
||||
local Tuple, Table, Struct, ArgumentTuple = ast.Tuple, ast.Table, ast.Struct, ast.ArgumentTuple
|
||||
local Tuple, Table, Struct, ArgumentTuple, Nil = ast.Tuple, ast.Table, ast.Struct, ast.ArgumentTuple, ast.Nil
|
||||
|
||||
local tag_manager = require("state.tag_manager")
|
||||
|
||||
|
|
@ -14,6 +14,8 @@ return {
|
|||
tags_struct = tags
|
||||
elseif Table:is(tags) then
|
||||
tags_struct = tags:to_struct(state)
|
||||
elseif Nil:is(tags) then
|
||||
tags_struct = Struct:new()
|
||||
else
|
||||
tags_struct = Struct:from_tuple(Tuple:new(tags)):eval(state)
|
||||
end
|
||||
|
|
|
|||
11
test/results/binary operator overload.ans
Normal file
11
test/results/binary operator overload.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"-3" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"heh minus lol" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"generic minus" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/binop assignement.ans
Normal file
9
test/results/binop assignement.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"1" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"3" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
15
test/results/choice block.ans
Normal file
15
test/results/choice block.ans
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
--# run #--
|
||||
--- choice ---
|
||||
> | {}"ye "|
|
||||
=> | {}"ne "|
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- choice ---
|
||||
=> | {}"ho "|
|
||||
> | {}"oh "|
|
||||
--- text ---
|
||||
| {}"plop"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
12
test/results/choice function.ans
Normal file
12
test/results/choice function.ans
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
--# run #--
|
||||
--- choice ---
|
||||
> | {}"ho "|
|
||||
> | {}"neol "|
|
||||
=> | {}"oh "|
|
||||
> | {}"neol "|
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
11
test/results/choice line interpolation with choice event.ans
Normal file
11
test/results/choice line interpolation with choice event.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {1:1}"A"|
|
||||
--- choice ---
|
||||
=> | {}"Suprise choice! "|
|
||||
> | {}"Press " {}"JOIN" {}" to jump. "|
|
||||
> | {}"No "|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
12
test/results/choice line interpolation with event flush.ans
Normal file
12
test/results/choice line interpolation with event flush.ans
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {1:1}"a"|
|
||||
--- choice ---
|
||||
=> | {}"Press " {}"SPLIT" {}" to jump. "|
|
||||
> | {}"No "|
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
19
test/results/choice line interpolation with text event.ans
Normal file
19
test/results/choice line interpolation with text event.ans
Normal 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 #--
|
||||
{}
|
||||
18
test/results/choice preserve tags.ans
Normal file
18
test/results/choice preserve tags.ans
Normal 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 #--
|
||||
{}
|
||||
10
test/results/choice simple.ans
Normal file
10
test/results/choice simple.ans
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
--# run #--
|
||||
--- choice ---
|
||||
> | {}"ye "|
|
||||
=> | {}"ne "|
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
11
test/results/closure.ans
Normal file
11
test/results/closure.ans
Normal 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
5
test/results/comment.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
--# run #--
|
||||
--- return ---
|
||||
8
|
||||
--# saved #--
|
||||
{}
|
||||
8
test/results/condition decorator.ans
Normal file
8
test/results/condition decorator.ans
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
| {}"ok bis"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/condition else false.ans
Normal file
7
test/results/condition else false.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/condition else true.ans
Normal file
7
test/results/condition else true.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/condition elseif false.ans
Normal file
7
test/results/condition elseif false.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/condition elseif true.ans
Normal file
7
test/results/condition elseif true.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
5
test/results/condition false.ans
Normal file
5
test/results/condition false.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
--# run #--
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/condition operator.ans
Normal file
9
test/results/condition operator.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a " {}"b" {}" c"|
|
||||
--- text ---
|
||||
| {}"a " {}"()" {}" c"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/condition true.ans
Normal file
7
test/results/condition true.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/constant variable.ans
Normal file
7
test/results/constant variable.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- error ---
|
||||
./state/State.lua:145: [0m[31m[0m[31mtrying to change the value of constant a[0m
|
||||
↳ from [4mtest/tests/constant variable.ans:5:3[0m in assignment: [2ma = 52[0m[0m
|
||||
↳ from [4m?[0m in block: [2m::a = 3…[0m
|
||||
--# saved #--
|
||||
{}
|
||||
8
test/results/custom text formatting.ans
Normal file
8
test/results/custom text formatting.ans
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"\"Name: Darmanin\\\
|
||||
Age: 38\"" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
4
test/results/define override function.ans
Normal file
4
test/results/define override function.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
--# parse error #--
|
||||
[0m[31m[0m[31ma is already defined in the current scope[0m
|
||||
↳ from [4mtest/tests/define override function.ans:4:4[0m in definition: [2m:a = 2[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:a = ($() _)…[0m
|
||||
5
test/results/define override variable.ans
Normal file
5
test/results/define override variable.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
--# parse error #--
|
||||
[0m[31m[0m[31m[0m[31mcan't add an overload variant to non-overloadable variable a defined in the same scope[0m
|
||||
↳ from [4mtest/tests/define override variable.ans:3:1[0m in definition: [2m:a = ($() _)[0m[0m
|
||||
↳ from [4mtest/tests/define override variable.ans:3:1[0m in attach block: [2m:a = ($() _)…[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:a = 2…[0m
|
||||
4
test/results/define override.ans
Normal file
4
test/results/define override.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
--# parse error #--
|
||||
[0m[31m[0m[31ma is already defined in the current scope[0m
|
||||
↳ from [4mtest/tests/define override.ans:3:4[0m in definition: [2m:a = 2[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:a = 5…[0m
|
||||
5
test/results/define.ans
Normal file
5
test/results/define.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
--# run #--
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
13
test/results/flush.ans
Normal file
13
test/results/flush.ans
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a"|
|
||||
--- choice ---
|
||||
=> | {}"b "|
|
||||
--- text ---
|
||||
| {}"c"|
|
||||
--- choice ---
|
||||
=> | {}"d "|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/function arg.ans
Normal file
7
test/results/function arg.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"ok" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/function args arity check fail.ans
Normal file
7
test/results/function args arity check fail.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- error ---
|
||||
./state/State.lua:145: [0m[31m[0m[31mcan't call closure ($(a, b) _): expected 2 arguments, received 1[0m
|
||||
↳ from [4mtest/tests/function args arity check fail.ans:4:2[0m in call: [2mf("ok")[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:f = ($(a, b) _)…[0m
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/function args.ans
Normal file
7
test/results/function args.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"o" {}"" {}"k" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
15
test/results/function assignement.ans
Normal file
15
test/results/function assignement.ans
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"5" {}""|
|
||||
--- text ---
|
||||
| {}"v=" {}"50" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"50" {}""|
|
||||
--- text ---
|
||||
| {}"v2=" {}"ok" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"3" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
15
test/results/function definition.ans
Normal file
15
test/results/function definition.ans
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"25" {}" = " {}"25" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"4" {}" = " {}"4" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"14" {}" == 14"|
|
||||
--- text ---
|
||||
| {}"" {}"32" {}" == 32"|
|
||||
--- text ---
|
||||
| {}"" {}"49" {}" == 49"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/function name dispatch.ans
Normal file
9
test/results/function name dispatch.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a"|
|
||||
--- text ---
|
||||
| {}"x"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
5
test/results/function no conflict.ans
Normal file
5
test/results/function no conflict.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
--# run #--
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/function return exit function.ans
Normal file
7
test/results/function return exit function.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"5" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/function return.ans
Normal file
7
test/results/function return.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"5" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/function scope wrong.ans
Normal file
9
test/results/function scope wrong.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- error ---
|
||||
./state/State.lua:145: [0m[31m[0m[31m[0m[31m[0m[31midentifier "b" is undefined in branch 0a138a38-3faa-4478-10f6f-1a9de1e0a8e1[0m
|
||||
↳ from [4mtest/tests/function scope wrong.ans:4:7[0m in identifier: [2mb[0m[0m
|
||||
↳ from [4mtest/tests/function scope wrong.ans:4:1[0m in text interpolation: [2m| a: {b}|[0m[0m
|
||||
↳ from [4mtest/tests/function scope wrong.ans:4:1[0m in translatable: [2m| a: {b}|[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:a = ($() _)…[0m
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/function scope.ans
Normal file
7
test/results/function scope.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a: " {}"5" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/function selection.ans
Normal file
9
test/results/function selection.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"plopheh" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"4" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/function type dispatch ambigous.ans
Normal file
9
test/results/function type dispatch ambigous.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- error ---
|
||||
./state/State.lua:145: [0m[31m[0m[31mcan'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>))[0m
|
||||
↳ from [4mtest/tests/function type dispatch ambigous.ans:7:3[0m in call: [2mfn(5)[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:fn = ($(x::number) _)…[0m
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/function type dispatch.ans
Normal file
9
test/results/function type dispatch.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a"|
|
||||
--- text ---
|
||||
| {}"x"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/function ufcs arg.ans
Normal file
9
test/results/function ufcs arg.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"ok" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"ok" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/function ufcs args.ans
Normal file
7
test/results/function ufcs args.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"o" {}"" {}"k" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/function.ans
Normal file
9
test/results/function.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"ok"|
|
||||
--- text ---
|
||||
| {}"ok2"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
15
test/results/implicit multiplication.ans
Normal file
15
test/results/implicit multiplication.ans
Normal 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 #--
|
||||
{}
|
||||
33
test/results/lazy boolean operators.ans
Normal file
33
test/results/lazy boolean operators.ans
Normal 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 #--
|
||||
{}
|
||||
17
test/results/list assignement.ans
Normal file
17
test/results/list assignement.ans
Normal 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: [0m[31m[0m[31mlist index out of bounds[0m
|
||||
↳ from [4mtest/tests/list assignement.ans:21:6[0m in call: [2mx(5) = 0[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:x = *[1, 2]…[0m
|
||||
--# saved #--
|
||||
{}
|
||||
17
test/results/list index.ans
Normal file
17
test/results/list index.ans
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"[1, 2, 3]" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"1" {}" == " {}"1" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"2" {}" == " {}"2" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"3" {}" == " {}"3" {}""|
|
||||
--- error ---
|
||||
./state/State.lua:145: [0m[31m[0m[31m[0m[31m[0m[31mtuple index out of bounds[0m
|
||||
↳ from [4mtest/tests/list index.ans:11:4[0m in call: [2mx(-4)[0m[0m
|
||||
↳ from [4mtest/tests/list index.ans:11:1[0m in text interpolation: [2m| {x(-4)}|[0m[0m
|
||||
↳ from [4mtest/tests/list index.ans:11:1[0m in translatable: [2m| {x(-4)}|[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:x = [1, 2, 3]…[0m
|
||||
--# saved #--
|
||||
{}
|
||||
28
test/results/loop decorator.ans
Normal file
28
test/results/loop decorator.ans
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"1" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"2" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"3" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"4" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"5" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"6" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"7" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"8" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"9" {}"" {}"\
|
||||
" {}""|
|
||||
| {}"" {}"10" {}"" {}"\
|
||||
" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"11" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
23
test/results/map assignement.ans
Normal file
23
test/results/map assignement.ans
Normal 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 #--
|
||||
{}
|
||||
11
test/results/map index.ans
Normal file
11
test/results/map index.ans
Normal 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 #--
|
||||
{}
|
||||
7
test/results/named arguments.ans
Normal file
7
test/results/named arguments.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"abc" {}" = " {}"abc" {}" = " {}"abc" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/namespace operator arbitrary expression.ans
Normal file
7
test/results/namespace operator arbitrary expression.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"5" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
10
test/results/nested conditions.ans
Normal file
10
test/results/nested conditions.ans
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"yes"|
|
||||
--- text ---
|
||||
| {}"ye"|
|
||||
| {}"da"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
20
test/results/nested flush.ans
Normal file
20
test/results/nested flush.ans
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a"|
|
||||
--- text ---
|
||||
| {}"b"|
|
||||
--- text ---
|
||||
| {}"c"|
|
||||
| {}"d"|
|
||||
--- text ---
|
||||
| {}"e"|
|
||||
--- choice ---
|
||||
=> | {}"f "|
|
||||
--- text ---
|
||||
| {}"g"|
|
||||
--- choice ---
|
||||
=> | {}"h "|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/optional arguments.ans
Normal file
7
test/results/optional arguments.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"abc" {}" = " {}"abc" {}" = " {}"abc" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/pair operator.ans
Normal file
9
test/results/pair operator.ans
Normal 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 #--
|
||||
{}
|
||||
10
test/results/return in choice.ans
Normal file
10
test/results/return in choice.ans
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
--# run #--
|
||||
--- choice ---
|
||||
=> | {}"a "|
|
||||
--- text ---
|
||||
| {}"x"|
|
||||
| {}"Yes."|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
14
test/results/string escaping.ans
Normal file
14
test/results/string escaping.ans
Normal 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 #--
|
||||
{}
|
||||
8
test/results/tag decorator nested.ans
Normal file
8
test/results/tag decorator nested.ans
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {1:1}"foo"|
|
||||
| {"a":[2, 3], "b":[1, 2], 1:1}"bar"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
8
test/results/tag decorator.ans
Normal file
8
test/results/tag decorator.ans
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {1:1}"foo"|
|
||||
| {"a":[2, 3], 1:1}"bar"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
8
test/results/tag empty.ans
Normal file
8
test/results/tag empty.ans
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {1:1}"foo"|
|
||||
| {1:1}"bar"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
8
test/results/tag.ans
Normal file
8
test/results/tag.ans
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {1:1}"foo"|
|
||||
| {"a":[2, 3], 1:1}"bar"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
11
test/results/text block.ans
Normal file
11
test/results/text block.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a"|
|
||||
| {}"b c"|
|
||||
--- text ---
|
||||
| {}"a"|
|
||||
| {}"b c"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
9
test/results/text break.ans
Normal file
9
test/results/text break.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a"|
|
||||
--- text ---
|
||||
| {}"b c"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
16
test/results/text escaping.ans
Normal file
16
test/results/text escaping.ans
Normal 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 #--
|
||||
{}
|
||||
7
test/results/text format.ans
Normal file
7
test/results/text format.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a: " {}"5" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
19
test/results/text line interpolation with choice event.ans
Normal file
19
test/results/text line interpolation with choice event.ans
Normal 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 #--
|
||||
{}
|
||||
13
test/results/text line interpolation with event flush.ans
Normal file
13
test/results/text line interpolation with event flush.ans
Normal 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 #--
|
||||
{}
|
||||
10
test/results/text line interpolation with text event.ans
Normal file
10
test/results/text line interpolation with text event.ans
Normal 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
7
test/results/text.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a"|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
11
test/results/unary operator overload.ans
Normal file
11
test/results/unary operator overload.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"-5" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"minus lol" {}""|
|
||||
--- text ---
|
||||
| {}"" {}"generic minus" {}""|
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
19
test/results/while loop else.ans
Normal file
19
test/results/while loop else.ans
Normal 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 #--
|
||||
{}
|
||||
41
test/results/while loop.ans
Normal file
41
test/results/while loop.ans
Normal 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 #--
|
||||
{}
|
||||
174
test/run.lua
174
test/run.lua
|
|
@ -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
|
||||
|
|
|
|||
11
test/tests/binary operator overload.ans
Normal file
11
test/tests/binary operator overload.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
:$ a - b
|
||||
@"generic minus"
|
||||
|
||||
:$ a::string - b::string
|
||||
@a + " minus " + b
|
||||
|
||||
| {2-5}
|
||||
|
||||
| {"heh"-"lol"}
|
||||
|
||||
| {[]-[]}
|
||||
7
test/tests/binop assignement.ans
Normal file
7
test/tests/binop assignement.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
:c = 1
|
||||
|
||||
|{c}
|
||||
|
||||
c += 2
|
||||
|
||||
|{c}
|
||||
11
test/tests/choice block.ans
Normal file
11
test/tests/choice block.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
:@choice = 2
|
||||
| ye |>
|
||||
| no
|
||||
| ne |>
|
||||
| ok
|
||||
|
||||
choice = 1
|
||||
| ho |>
|
||||
| plop
|
||||
| oh |>
|
||||
| plup
|
||||
11
test/tests/choice function.ans
Normal file
11
test/tests/choice function.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
:$ f
|
||||
| neol |>
|
||||
| nah
|
||||
|
||||
| ho |>
|
||||
|plop
|
||||
f!
|
||||
| oh |>
|
||||
|ok
|
||||
f!
|
||||
:@choice=3
|
||||
11
test/tests/choice line interpolation with choice event.ans
Normal file
11
test/tests/choice line interpolation with choice event.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
:@choice=1
|
||||
|
||||
:$ jump button
|
||||
1 # |A
|
||||
| Suprise choice! |> ()
|
||||
@"JOIN"
|
||||
|
||||
| Press {jump button!} to jump. |>
|
||||
|ok
|
||||
| No |>
|
||||
|ko
|
||||
11
test/tests/choice line interpolation with event flush.ans
Normal file
11
test/tests/choice line interpolation with event flush.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
:@choice=1
|
||||
|
||||
:$ jump button
|
||||
1 # | a
|
||||
|
||||
@"SPLIT"
|
||||
|
||||
| Press {jump button!} to jump. |>
|
||||
| ok
|
||||
| No |>
|
||||
| ko
|
||||
17
test/tests/choice line interpolation with text event.ans
Normal file
17
test/tests/choice line interpolation with text event.ans
Normal 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
|
||||
16
test/tests/choice preserve tags.ans
Normal file
16
test/tests/choice preserve tags.ans
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
:choice = 1
|
||||
|
||||
:$ f
|
||||
42 #
|
||||
| a |>
|
||||
| b
|
||||
|
||||
f!
|
||||
| c |> ()
|
||||
|
||||
"k":"v" #
|
||||
f!
|
||||
| d |> ()
|
||||
| e
|
||||
|
||||
| f
|
||||
5
test/tests/choice simple.ans
Normal file
5
test/tests/choice simple.ans
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
| ye |>
|
||||
| no
|
||||
| ne |>
|
||||
| ok
|
||||
:@choice = 2
|
||||
12
test/tests/closure.ans
Normal file
12
test/tests/closure.ans
Normal 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
9
test/tests/comment.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
((hey couic + 5))
|
||||
|
||||
((nested ((comments)) d))
|
||||
|
||||
2 ((end of line))
|
||||
|
||||
((start of line)) 3
|
||||
|
||||
5 + ((middle)) 3
|
||||
3
test/tests/condition decorator.ans
Normal file
3
test/tests/condition decorator.ans
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
() ~ |ko
|
||||
1 ~ |ok
|
||||
1 ~ |ok bis
|
||||
6
test/tests/condition else false.ans
Normal file
6
test/tests/condition else false.ans
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
:a = 5
|
||||
|
||||
a == 2 ~
|
||||
|ko
|
||||
~
|
||||
|ok
|
||||
6
test/tests/condition else true.ans
Normal file
6
test/tests/condition else true.ans
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
:a = 5
|
||||
|
||||
a == 5 ~
|
||||
|ok
|
||||
~
|
||||
|ko
|
||||
8
test/tests/condition elseif false.ans
Normal file
8
test/tests/condition elseif false.ans
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
:a = 5
|
||||
|
||||
a == 2 ~
|
||||
|ko
|
||||
~ () ~
|
||||
|ko
|
||||
~
|
||||
|ok
|
||||
8
test/tests/condition elseif true.ans
Normal file
8
test/tests/condition elseif true.ans
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
:a = 5
|
||||
|
||||
a == 2 ~
|
||||
|ko
|
||||
~ 1 ~
|
||||
|ok
|
||||
~
|
||||
|ko
|
||||
4
test/tests/condition false.ans
Normal file
4
test/tests/condition false.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:a = 5
|
||||
|
||||
a == 2 ~
|
||||
|ko
|
||||
6
test/tests/condition operator.ans
Normal file
6
test/tests/condition operator.ans
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
:$ f
|
||||
@|b
|
||||
|
||||
|a {5 ~ f!} c
|
||||
|
||||
|a {() ~ f!} c
|
||||
4
test/tests/condition true.ans
Normal file
4
test/tests/condition true.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:a = 5
|
||||
|
||||
a == 5 ~
|
||||
|ok
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue