From 9b7d1e436e48093bff54311b33db30e984d50624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Fri, 29 Dec 2023 17:15:43 +0100 Subject: [PATCH] Second test batch and associated fixes --- ast/AttachBlock.lua | 4 +- ast/Definition.lua | 9 +-- ast/Environment.lua | 8 +-- ast/abstract/Node.lua | 2 +- state/State.lua | 13 +++- test/results/choice with decorators.ans | 33 ++++++++++ test/results/constant variable list.ans | 9 +++ test/results/constant variable.ans | 2 +- .../constrained variable assignement.ans | 11 ++++ .../constrained variable definition.ans | 9 +++ test/results/define override function.ans | 7 +- test/results/define override variable.ans | 7 +- test/results/define override.ans | 7 +- test/results/equality operator.ans | 27 ++++++++ test/results/exported variable.ans | 5 ++ .../function args arity check fail.ans | 2 +- test/results/function exported.ans | 21 ++++++ .../function return exit function nested.ans | 8 +++ test/results/function return nested.ans | 8 +++ test/results/function scope wrong.ans | 2 +- test/results/function scoped mutable.ans | 65 +++++++++++++++++++ test/results/function scoped nested.ans | 61 +++++++++++++++++ test/results/function scoped recursive.ans | 33 ++++++++++ test/results/function scoped.ans | 21 ++++++ ...nction separate variable from variants.ans | 12 ++++ .../function type dispatch ambigous.ans | 2 +- test/results/list assignement.ans | 2 +- test/results/list index.ans | 2 +- test/results/return children.ans | 9 +++ test/results/tag operator.ans | 9 +++ test/results/text buffer with tags.ans | 7 ++ test/results/text buffer.ans | 7 ++ test/results/translate context.ans | 11 ++++ test/results/translate string.ans | 9 +++ test/results/translate text.ans | 9 +++ test/tests/choice with decorators.ans | 35 ++++++++++ test/tests/constant variable list.ans | 7 ++ .../constrained variable assignement.ans | 11 ++++ .../tests/constrained variable definition.ans | 7 ++ test/tests/equality operator.ans | 29 +++++++++ test/tests/exported variable.ans | 4 ++ test/tests/function exported.ans | 29 +++++++++ .../function return exit function nested.ans | 9 +++ test/tests/function return nested.ans | 7 ++ test/tests/function scoped mutable.ans | 40 ++++++++++++ test/tests/function scoped nested.ans | 44 +++++++++++++ test/tests/function scoped recursive.ans | 19 ++++++ test/tests/function scoped.ans | 29 +++++++++ ...nction separate variable from variants.ans | 10 +++ test/tests/return children.ans | 13 ++++ test/tests/tag operator.ans | 7 ++ test/tests/text buffer with tags.ans | 8 +++ test/tests/text buffer.ans | 8 +++ test/tests/translate context.ans | 8 +++ test/tests/translate string.ans | 5 ++ test/tests/translate text.ans | 5 ++ 56 files changed, 760 insertions(+), 27 deletions(-) create mode 100644 test/results/choice with decorators.ans create mode 100644 test/results/constant variable list.ans create mode 100644 test/results/constrained variable assignement.ans create mode 100644 test/results/constrained variable definition.ans create mode 100644 test/results/equality operator.ans create mode 100644 test/results/exported variable.ans create mode 100644 test/results/function exported.ans create mode 100644 test/results/function return exit function nested.ans create mode 100644 test/results/function return nested.ans create mode 100644 test/results/function scoped mutable.ans create mode 100644 test/results/function scoped nested.ans create mode 100644 test/results/function scoped recursive.ans create mode 100644 test/results/function scoped.ans create mode 100644 test/results/function separate variable from variants.ans create mode 100644 test/results/return children.ans create mode 100644 test/results/tag operator.ans create mode 100644 test/results/text buffer with tags.ans create mode 100644 test/results/text buffer.ans create mode 100644 test/results/translate context.ans create mode 100644 test/results/translate string.ans create mode 100644 test/results/translate text.ans create mode 100644 test/tests/choice with decorators.ans create mode 100644 test/tests/constant variable list.ans create mode 100644 test/tests/constrained variable assignement.ans create mode 100644 test/tests/constrained variable definition.ans create mode 100644 test/tests/equality operator.ans create mode 100644 test/tests/exported variable.ans create mode 100644 test/tests/function exported.ans create mode 100644 test/tests/function return exit function nested.ans create mode 100644 test/tests/function return nested.ans create mode 100644 test/tests/function scoped mutable.ans create mode 100644 test/tests/function scoped nested.ans create mode 100644 test/tests/function scoped recursive.ans create mode 100644 test/tests/function scoped.ans create mode 100644 test/tests/function separate variable from variants.ans create mode 100644 test/tests/return children.ans create mode 100644 test/tests/tag operator.ans create mode 100644 test/tests/text buffer with tags.ans create mode 100644 test/tests/text buffer.ans create mode 100644 test/tests/translate context.ans create mode 100644 test/tests/translate string.ans create mode 100644 test/tests/translate text.ans diff --git a/ast/AttachBlock.lua b/ast/AttachBlock.lua index 3f926b8..b1de863 100644 --- a/ast/AttachBlock.lua +++ b/ast/AttachBlock.lua @@ -17,7 +17,9 @@ AttachBlock = ast.abstract.Node { end, _format = function(self, state, priority, indentation, ...) - return self.expression:format(state, priority, indentation, ...).."\n\t"..self.block:format(state, priority, indentation + 1, ...) + local exp = self.expression:format(state, priority, indentation, ...) + if exp:sub(-2) == " _" then exp = exp:sub(1, -3) end + return exp.."\n\t"..self.block:format(state, priority, indentation + 1, ...) end, traverse = function(self, fn, ...) diff --git a/ast/Definition.lua b/ast/Definition.lua index 7f198e7..c3de2f6 100644 --- a/ast/Definition.lua +++ b/ast/Definition.lua @@ -50,12 +50,9 @@ local Definition = ast.abstract.Node { symbol:prepare(state) val:prepare(state) - if self.symbol.alias then - state.scope:define(symbol:with{ alias = false }, val) -- disable alias to avoid call in Identifier:_prepare - elseif Overloadable:issub(val) then - state.scope:define_overloadable(symbol, val) - else - state.scope:define(symbol, val) + -- predefine exported variables + if symbol.exported then + self:eval(state) end end } diff --git a/ast/Environment.lua b/ast/Environment.lua index 6697f79..b9b7d87 100644 --- a/ast/Environment.lua +++ b/ast/Environment.lua @@ -28,7 +28,7 @@ local VariableMetadata = ast.abstract.Runtime { 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 + 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), 0) end end if self.symbol.alias then local assign_args = ArgumentTuple:new() @@ -185,14 +185,12 @@ local Environment = ast.abstract.Runtime { return self:_get_variable(state, identifier):set(state, val) end, - -- returns a list {[symbol]=val,...} of all exported variables in the current strict layer + -- returns a list {[symbol]=val,...} of all exported variables (evaluated) in the current strict layer list_exported = function(self, state) assert(self.export, "not an export scope layer") local r = {} for _, vm in self.variables:iter(state) do - if vm.symbol.exported then - r[vm.symbol] = vm:get(state) - end + r[vm.symbol] = vm:get(state) end return r end, diff --git a/ast/abstract/Node.lua b/ast/abstract/Node.lua index 7ca1106..989fd7b 100644 --- a/ast/abstract/Node.lua +++ b/ast/abstract/Node.lua @@ -165,7 +165,7 @@ Node = class { local r = {} for _, tr in ipairs(l) do table.insert(r, "(("..tr.source.."))") - table.insert(r, Call:new(Identifier:new("_#_"), ArgumentTuple:new(tr.context, Identifier:new("_")))) + table.insert(r, Call:new(Identifier:new("_#_"), ArgumentTuple:new(tr.context, Identifier:new("_"))):format()) table.insert(r, "\t"..Call:new(Identifier:new("_->_"), ArgumentTuple:new(tr, tr)):format()) table.insert(r, "") end diff --git a/state/State.lua b/state/State.lua index cc0f5a8..53dacf6 100644 --- a/state/State.lua +++ b/state/State.lua @@ -12,6 +12,15 @@ local parser = require("parser") local binser = require("lib.binser") local anselme +-- same as assert, but do not add position information +-- useful for errors raised from anselme (don't care about Lua error position) +local function assert0(v, message, ...) + if not v then + error(message, 0) + end + return v, message, ... +end + local State State = class { type = "anselme state", @@ -142,7 +151,7 @@ State = class { run = function(self, code, source) assert(not self:active(), "a script is already active") self._coroutine = coroutine.create(function() - local r = assert(self:eval_local(code, source)) + local r = assert0(self:eval_local(code, source)) event_manager:final_flush(self) return "return", r end) @@ -174,7 +183,7 @@ State = class { assert(self:active(), "trying to interrupt but no script is currently active") if code then self._coroutine = coroutine.create(function() - local r = assert(self:eval_local(code, source)) + local r = assert0(self:eval_local(code, source)) event_manager:final_flush(self) self.scope:reset() -- scope stack is probably messed up after the switch return "return", r diff --git a/test/results/choice with decorators.ans b/test/results/choice with decorators.ans new file mode 100644 index 0000000..015b8b2 --- /dev/null +++ b/test/results/choice with decorators.ans @@ -0,0 +1,33 @@ +--# run #-- +--- choice --- +=> | {}"a "| + > | {}"b "| +--- text --- +| {}"-> a"| +--- choice --- + > | {}"a "| +=> | {}"b "| +--- text --- +| {}"-> b"| +--- choice --- +=> | {}"b "| +--- text --- +| {}"-> b"| +--- choice --- + > | {}"a "| +=> | {1:25}"b "| +--- text --- +| {1:25}"-> b"| +--- choice --- +=> | {1:3}"b "| +--- text --- +| {1:3}"-> b"| +--- choice --- +=> | {1:12}"a "| + > | {1:3}"b "| +--- text --- +| {1:12}"-> a"| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/constant variable list.ans b/test/results/constant variable list.ans new file mode 100644 index 0000000..e1ded19 --- /dev/null +++ b/test/results/constant variable list.ans @@ -0,0 +1,9 @@ +--# run #-- +--- text --- +| {}"" {}"*[3]" {}""| +--- text --- +| {}"" {}"*[3, 52]" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/constant variable.ans b/test/results/constant variable.ans index 461df20..53dc1fc 100644 --- a/test/results/constant variable.ans +++ b/test/results/constant variable.ans @@ -1,6 +1,6 @@ --# run #-- --- error --- -./state/State.lua:145: trying to change the value of constant a +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 #-- diff --git a/test/results/constrained variable assignement.ans b/test/results/constrained variable assignement.ans new file mode 100644 index 0000000..fe00758 --- /dev/null +++ b/test/results/constrained variable assignement.ans @@ -0,0 +1,11 @@ +--# run #-- +--- text --- +| {}"" {}"type(\"kg\", 5)" {}""| +--- text --- +| {}"" {}"type(\"kg\", 12)" {}""| +--- error --- +type check failure for weigh; 32 does not satisfy ($(x) type(x) == t) + ↳ from test/tests/constrained variable assignement.ans:9:7 in assignment: weigh = 32 + ↳ from ? in block: :weigh::is("kg") = type(5, "kg")… +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/constrained variable definition.ans b/test/results/constrained variable definition.ans new file mode 100644 index 0000000..d6477a8 --- /dev/null +++ b/test/results/constrained variable definition.ans @@ -0,0 +1,9 @@ +--# run #-- +--- text --- +| {}"" {}"type(\"kg\", 5)" {}""| +--- text --- +| {}"" {}"12" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/define override function.ans b/test/results/define override function.ans index cf2c11a..b548d21 100644 --- a/test/results/define override function.ans +++ b/test/results/define override function.ans @@ -1,4 +1,7 @@ ---# parse error #-- +--# run #-- +--- 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 = ($() _)… \ No newline at end of file + ↳ from ? in block: :a = ($() _)… +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/define override variable.ans b/test/results/define override variable.ans index 1c922d9..469dd0c 100644 --- a/test/results/define override variable.ans +++ b/test/results/define override variable.ans @@ -1,5 +1,8 @@ ---# parse error #-- +--# run #-- +--- 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… \ No newline at end of file + ↳ from ? in block: :a = 2… +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/define override.ans b/test/results/define override.ans index 07b429f..770be88 100644 --- a/test/results/define override.ans +++ b/test/results/define override.ans @@ -1,4 +1,7 @@ ---# parse error #-- +--# run #-- +--- 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… \ No newline at end of file + ↳ from ? in block: :a = 5… +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/equality operator.ans b/test/results/equality operator.ans new file mode 100644 index 0000000..e8c3af5 --- /dev/null +++ b/test/results/equality operator.ans @@ -0,0 +1,27 @@ +--# run #-- +--- text --- +| {}"false = " {}"false" {}""| +--- text --- +| {}"false = " {}"false" {}""| +--- text --- +| {}"true = " {}"true" {}""| +--- text --- +| {}"false = " {}"false" {}""| +--- text --- +| {}"false = " {}"false" {}""| +--- text --- +| {}"false = " {}"false" {}""| +--- text --- +| {}"false = " {}"false" {}""| +--- text --- +| {}"true = " {}"true" {}""| +--- text --- +| {}"false = " {}"false" {}""| +--- text --- +| {}"true = " {}"true" {}""| +--- text --- +| {}"true = " {}"true" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/exported variable.ans b/test/results/exported variable.ans new file mode 100644 index 0000000..b4e9fb8 --- /dev/null +++ b/test/results/exported variable.ans @@ -0,0 +1,5 @@ +--# run #-- +--- return --- +"ok" +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function args arity check fail.ans b/test/results/function args arity check fail.ans index b748246..bb3da2b 100644 --- a/test/results/function args arity check fail.ans +++ b/test/results/function args arity check fail.ans @@ -1,6 +1,6 @@ --# run #-- --- error --- -./state/State.lua:145: can't call closure ($(a, b) _): expected 2 arguments, received 1 +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 #-- diff --git a/test/results/function exported.ans b/test/results/function exported.ans new file mode 100644 index 0000000..01c0f71 --- /dev/null +++ b/test/results/function exported.ans @@ -0,0 +1,21 @@ +--# run #-- +--- text --- +| {}"local:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"exported:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"2" {}""| +--- text --- +| {}"" {}"3" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function return exit function nested.ans b/test/results/function return exit function nested.ans new file mode 100644 index 0000000..bb6fb05 --- /dev/null +++ b/test/results/function return exit function nested.ans @@ -0,0 +1,8 @@ +--# run #-- +--- text --- +| {}"" {}"5" {}""| +| {}"" {}"2" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function return nested.ans b/test/results/function return nested.ans new file mode 100644 index 0000000..bb6fb05 --- /dev/null +++ b/test/results/function return nested.ans @@ -0,0 +1,8 @@ +--# run #-- +--- text --- +| {}"" {}"5" {}""| +| {}"" {}"2" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function scope wrong.ans b/test/results/function scope wrong.ans index 96d8388..a958b30 100644 --- a/test/results/function scope wrong.ans +++ b/test/results/function scope wrong.ans @@ -1,6 +1,6 @@ --# run #-- --- error --- -./state/State.lua:145: identifier "b" is undefined in branch 0a138a38-3faa-4478-10f6f-1a9de1e0a8e1 +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}| diff --git a/test/results/function scoped mutable.ans b/test/results/function scoped mutable.ans new file mode 100644 index 0000000..313fa5d --- /dev/null +++ b/test/results/function scoped mutable.ans @@ -0,0 +1,65 @@ +--# run #-- +--- text --- +| {}"new list each time:"| +--- text --- +| {}"start: " {}"*[]" {}""| +--- text --- +| {}"before recursion " {}"1" {}": " {}"*[1]" {}""| +--- text --- +| {}"start: " {}"*[]" {}""| +--- text --- +| {}"before recursion " {}"2" {}": " {}"*[2]" {}""| +--- text --- +| {}"start: " {}"*[]" {}""| +--- text --- +| {}"before recursion " {}"3" {}": " {}"*[3]" {}""| +--- text --- +| {}"start: " {}"*[]" {}""| +--- text --- +| {}"before recursion " {}"4" {}": " {}"*[4]" {}""| +--- text --- +| {}"start: " {}"*[]" {}""| +--- text --- +| {}"before recursion " {}"5" {}": " {}"*[5]" {}""| +--- text --- +| {}"after recursion " {}"4" {}": " {}"*[4]" {}""| +--- text --- +| {}"after recursion " {}"3" {}": " {}"*[3]" {}""| +--- text --- +| {}"after recursion " {}"2" {}": " {}"*[2]" {}""| +--- text --- +| {}"after recursion " {}"1" {}": " {}"*[1]" {}""| +--- text --- +| {}"pass list:"| +--- text --- +| {}"start: " {}"*[]" {}""| +--- text --- +| {}"before recursion " {}"1" {}": " {}"*[1]" {}""| +--- text --- +| {}"start: " {}"*[1]" {}""| +--- text --- +| {}"before recursion " {}"2" {}": " {}"*[1, 2]" {}""| +--- text --- +| {}"start: " {}"*[1, 2]" {}""| +--- text --- +| {}"before recursion " {}"3" {}": " {}"*[1, 2, 3]" {}""| +--- text --- +| {}"start: " {}"*[1, 2, 3]" {}""| +--- text --- +| {}"before recursion " {}"4" {}": " {}"*[1, 2, 3, 4]" {}""| +--- text --- +| {}"start: " {}"*[1, 2, 3, 4]" {}""| +--- text --- +| {}"before recursion " {}"5" {}": " {}"*[1, 2, 3, 4, 5]" {}""| +--- text --- +| {}"after recursion " {}"4" {}": " {}"*[1, 2, 3, 4, 5]" {}""| +--- text --- +| {}"after recursion " {}"3" {}": " {}"*[1, 2, 3, 4, 5]" {}""| +--- text --- +| {}"after recursion " {}"2" {}": " {}"*[1, 2, 3, 4, 5]" {}""| +--- text --- +| {}"after recursion " {}"1" {}": " {}"*[1, 2, 3, 4, 5]" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function scoped nested.ans b/test/results/function scoped nested.ans new file mode 100644 index 0000000..6e30fb1 --- /dev/null +++ b/test/results/function scoped nested.ans @@ -0,0 +1,61 @@ +--# run #-- +--- text --- +| {}"depth 1:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}">" {}" depth 2, unscoped:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}">" {}" depth 2, scoped:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}">" {}" depth 2, unscoped:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}">" {}" depth 2, scoped:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}">" {}" depth 2, unscoped:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}">" {}" depth 2, scoped:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function scoped recursive.ans b/test/results/function scoped recursive.ans new file mode 100644 index 0000000..09a9cff --- /dev/null +++ b/test/results/function scoped recursive.ans @@ -0,0 +1,33 @@ +--# run #-- +--- text --- +| {}"start: " {}"1" {}""| +--- text --- +| {}"before recursion " {}"1" {}": " {}"2" {}""| +--- text --- +| {}"start: " {}"1" {}""| +--- text --- +| {}"before recursion " {}"2" {}": " {}"2" {}""| +--- text --- +| {}"start: " {}"1" {}""| +--- text --- +| {}"before recursion " {}"3" {}": " {}"2" {}""| +--- text --- +| {}"start: " {}"1" {}""| +--- text --- +| {}"before recursion " {}"4" {}": " {}"2" {}""| +--- text --- +| {}"start: " {}"1" {}""| +--- text --- +| {}"before recursion " {}"5" {}": " {}"2" {}""| +--- text --- +| {}"after recursion " {}"4" {}": " {}"2" {}""| +--- text --- +| {}"after recursion " {}"3" {}": " {}"2" {}""| +--- text --- +| {}"after recursion " {}"2" {}": " {}"2" {}""| +--- text --- +| {}"after recursion " {}"1" {}": " {}"2" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function scoped.ans b/test/results/function scoped.ans new file mode 100644 index 0000000..a785596 --- /dev/null +++ b/test/results/function scoped.ans @@ -0,0 +1,21 @@ +--# run #-- +--- text --- +| {}"paren:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"no paren:"| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- text --- +| {}"" {}"1" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function separate variable from variants.ans b/test/results/function separate variable from variants.ans new file mode 100644 index 0000000..16295b8 --- /dev/null +++ b/test/results/function separate variable from variants.ans @@ -0,0 +1,12 @@ +--# run #-- +--- error --- +can't call overload overload<($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) )>: no function match (overload<($(b) _), ($(x) _), ($() _)>, "a"), possible functions were: + • (c::($(x) ), s::($(x) )) = v: expected 3 arguments, received 2 + • (c::($(x) ), s::($(x) )) = v: expected 3 arguments, received 2 + • (c::($(x) ), s::($(x) )): type check failure for parameter c in function (c::($(x) ), s::($(x) )) + ↳ from test/tests/function separate variable from variants.ans:10:4 in call: f . "a" + ↳ from test/tests/function separate variable from variants.ans:10:1 in text interpolation: | {(f . "a")} = 2| + ↳ from test/tests/function separate variable from variants.ans:10:1 in translatable: | {(f . "a")} = 2| + ↳ from ? in block: :f = ($() _)… +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function type dispatch ambigous.ans b/test/results/function type dispatch ambigous.ans index 12c9ef2..8d6a596 100644 --- a/test/results/function type dispatch ambigous.ans +++ b/test/results/function type dispatch ambigous.ans @@ -1,6 +1,6 @@ --# run #-- --- error --- -./state/State.lua:145: can't call overload overload<($(a::($(x) )) _), ($(x::($(x) )) _)>: more than one function match (5), matching functions were at least (specificity 1.3): +can't call overload overload<($(a::($(x) )) _), ($(x::($(x) )) _)>: more than one function match (5), matching functions were at least (specificity 1.3): • (x::($(x) )) • (a::($(x) )) ↳ from test/tests/function type dispatch ambigous.ans:7:3 in call: fn(5) diff --git a/test/results/list assignement.ans b/test/results/list assignement.ans index 9dc8ed4..c25f8b1 100644 --- a/test/results/list assignement.ans +++ b/test/results/list assignement.ans @@ -10,7 +10,7 @@ --- text --- | {}"" {}"*[3, 12, 99]" {}""| --- error --- -./state/State.lua:145: list index out of bounds +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 #-- diff --git a/test/results/list index.ans b/test/results/list index.ans index e184f32..51a5ad5 100644 --- a/test/results/list index.ans +++ b/test/results/list index.ans @@ -8,7 +8,7 @@ --- text --- | {}"" {}"3" {}" == " {}"3" {}""| --- error --- -./state/State.lua:145: tuple index out of bounds +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)}| diff --git a/test/results/return children.ans b/test/results/return children.ans new file mode 100644 index 0000000..64ca15d --- /dev/null +++ b/test/results/return children.ans @@ -0,0 +1,9 @@ +--# run #-- +--- text --- +| {}"" {}"50" {}" = 50"| +--- text --- +| {}"" {}"3" {}" = 3"| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/tag operator.ans b/test/results/tag operator.ans new file mode 100644 index 0000000..4f41cdd --- /dev/null +++ b/test/results/tag operator.ans @@ -0,0 +1,9 @@ +--# run #-- +--- text --- +| {}"a " {1:5}"" {1:5}"b" {1:5}"" {}" c"| +--- text --- +| {2:2}"a " {1:5, 2:2}"" {1:5, 2:2}"b" {1:5, 2:2}"" {2:2}" c"| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/text buffer with tags.ans b/test/results/text buffer with tags.ans new file mode 100644 index 0000000..9d861b1 --- /dev/null +++ b/test/results/text buffer with tags.ans @@ -0,0 +1,7 @@ +--# run #-- +--- text --- +| {1:1}"lol"| +--- return --- +@| {}"a " {1:2}"d" {}" " {1:3}"t" {}" b"| +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/text buffer.ans b/test/results/text buffer.ans new file mode 100644 index 0000000..2657e45 --- /dev/null +++ b/test/results/text buffer.ans @@ -0,0 +1,7 @@ +--# run #-- +--- text --- +| {}"lol"| +--- return --- +@| {}"a " {}"d" {}" b"| +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/translate context.ans b/test/results/translate context.ans new file mode 100644 index 0000000..c76ecc7 --- /dev/null +++ b/test/results/translate context.ans @@ -0,0 +1,11 @@ +--# run #-- +--- text --- +| {}"Hello"| +--- text --- +| {}"Bonjour"| +--- text --- +| {}"Hello"| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/translate string.ans b/test/results/translate string.ans new file mode 100644 index 0000000..34c794f --- /dev/null +++ b/test/results/translate string.ans @@ -0,0 +1,9 @@ +--# run #-- +--- text --- +| {}"" {}"Hello" {}""| +--- text --- +| {}"" {}"Bonjour" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/translate text.ans b/test/results/translate text.ans new file mode 100644 index 0000000..0c9983f --- /dev/null +++ b/test/results/translate text.ans @@ -0,0 +1,9 @@ +--# run #-- +--- text --- +| {}"Hello"| +--- text --- +| {}"Bonjour"| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/tests/choice with decorators.ans b/test/tests/choice with decorators.ans new file mode 100644 index 0000000..effccdc --- /dev/null +++ b/test/tests/choice with decorators.ans @@ -0,0 +1,35 @@ +1 ~ | a |> + | -> a +| b |> + | -> b +:@choice = 1 + +1 ~ | a |> + | -> a +| b |> + | -> b +choice = 2 + +() ~ | a |> + | -> a +| b |> + | -> b +choice = 1 + +| a |> + | -> a +25 # | b |> + | -> b +choice = 2 + +12 # () ~ | a |> + | -> a +3 # | b |> + | -> b +choice = 1 + +12 # 1 ~ | a |> + | -> a +3 # | b |> + | -> b +choice = 1 diff --git a/test/tests/constant variable list.ans b/test/tests/constant variable list.ans new file mode 100644 index 0000000..144a31f --- /dev/null +++ b/test/tests/constant variable list.ans @@ -0,0 +1,7 @@ +::a = *[3] + +|{a} + +a!insert(52) + +|{a} diff --git a/test/tests/constrained variable assignement.ans b/test/tests/constrained variable assignement.ans new file mode 100644 index 0000000..6ba40f2 --- /dev/null +++ b/test/tests/constrained variable assignement.ans @@ -0,0 +1,11 @@ +:weigh::is("kg") = 5!type("kg") + +|{weigh} + +weigh = 12!type("kg") + +|{weigh} + +weigh = 32 + +|{weigh} diff --git a/test/tests/constrained variable definition.ans b/test/tests/constrained variable definition.ans new file mode 100644 index 0000000..2232920 --- /dev/null +++ b/test/tests/constrained variable definition.ans @@ -0,0 +1,7 @@ +:weigh::($(x)x!type=="kg") = type(5, "kg") + +|{weigh} + +:not weigh::($(x)x!type=="kg") = 12 + +|{not weigh} diff --git a/test/tests/equality operator.ans b/test/tests/equality operator.ans new file mode 100644 index 0000000..0fe785c --- /dev/null +++ b/test/tests/equality operator.ans @@ -0,0 +1,29 @@ +::a = [1:2] + +|false = {a == [5:2]} + +|false = {a == [1:3]} + +|true = {a == [1:2]} + +::b = [1,2,3] + +|false = {b == a} + +|false = {b == []} + +|false = {b == [3,1,2]} + +|false = {b == [1,2,3,4]} + +|true = {b == [1,2,3]} + +:c = *[1,2,3] + +|false = {c == b} + +|true = {c!to tuple == b} + +::d = [1,2,3] + +|true = {d == b} diff --git a/test/tests/exported variable.ans b/test/tests/exported variable.ans new file mode 100644 index 0000000..12b0cb0 --- /dev/null +++ b/test/tests/exported variable.ans @@ -0,0 +1,4 @@ +:f = $ + :@x = "ok" + +f.x \ No newline at end of file diff --git a/test/tests/function exported.ans b/test/tests/function exported.ans new file mode 100644 index 0000000..4f3dbe2 --- /dev/null +++ b/test/tests/function exported.ans @@ -0,0 +1,29 @@ +:$ f + :a = 1 + + |{a} + + a = a + 1 + +:$ g + :@a = 1 + + |{a} + + a = a + 1 + +|local: + +f! + +f! + +f! + +|exported: + +g! + +g! + +g! \ No newline at end of file diff --git a/test/tests/function return exit function nested.ans b/test/tests/function return exit function nested.ans new file mode 100644 index 0000000..c2b102e --- /dev/null +++ b/test/tests/function return exit function nested.ans @@ -0,0 +1,9 @@ +:$ hey + :@$ foo + @2 + @3 + @5 + |u + +|{hey!} +|{hey.foo!} \ No newline at end of file diff --git a/test/tests/function return nested.ans b/test/tests/function return nested.ans new file mode 100644 index 0000000..17bc913 --- /dev/null +++ b/test/tests/function return nested.ans @@ -0,0 +1,7 @@ +:$ hey + :@$ foo + @2 + @5 + +|{hey!} +|{hey.foo!} \ No newline at end of file diff --git a/test/tests/function scoped mutable.ans b/test/tests/function scoped mutable.ans new file mode 100644 index 0000000..1084243 --- /dev/null +++ b/test/tests/function scoped mutable.ans @@ -0,0 +1,40 @@ +:n = 0 + +:$ f(c=1) + :a = *[] + + |start: {a} + + a!insert(c) + + n += 1 + + |before recursion {c}: {a} + + n < 5 ~ + f(c+1) + + |after recursion {c}: {a} + +|new list each time: + +f! + +:$ g(c=1, a=*[]) + |start: {a} + + a!insert(c) + + n += 1 + + |before recursion {c}: {a} + + n < 5 ~ + g(c+1, a) + + |after recursion {c}: {a} + +|pass list: + +n = 0 +g! diff --git a/test/tests/function scoped nested.ans b/test/tests/function scoped nested.ans new file mode 100644 index 0000000..1ca5939 --- /dev/null +++ b/test/tests/function scoped nested.ans @@ -0,0 +1,44 @@ +:$ f() + :a = 1 + + |{a} + + a = a + 1 + + :$ g + :a = 1 + + |{a} + + a = a + 1 + + :$ h() + :a = 1 + + |{a} + + a = a + 1 + + |\> depth 2, unscoped: + + g! + + g! + + g! + + |\> depth 2, scoped: + + h! + + h! + + h! + +|depth 1: + +f! + +f! + +f! diff --git a/test/tests/function scoped recursive.ans b/test/tests/function scoped recursive.ans new file mode 100644 index 0000000..b5241ac --- /dev/null +++ b/test/tests/function scoped recursive.ans @@ -0,0 +1,19 @@ +:n = 0 + +:$ f(c=1) + :a = 1 + + |start: {a} + + a = a + 1 + + n += 1 + + |before recursion {c}: {a} + + n < 5 ~ + f(c+1) + + |after recursion {c}: {a} + +f! diff --git a/test/tests/function scoped.ans b/test/tests/function scoped.ans new file mode 100644 index 0000000..1061e18 --- /dev/null +++ b/test/tests/function scoped.ans @@ -0,0 +1,29 @@ +:$ f() + :a = 1 + + |{a} + + a = a + 1 + +:$ g + :a = 1 + + |{a} + + a = a + 1 + +|paren: + +f! + +f! + +f! + +|no paren: + +g! + +g! + +g! \ No newline at end of file diff --git a/test/tests/function separate variable from variants.ans b/test/tests/function separate variable from variants.ans new file mode 100644 index 0000000..d078e0f --- /dev/null +++ b/test/tests/function separate variable from variants.ans @@ -0,0 +1,10 @@ +:$ f + :@a = 2 + +:$ f(x) + :a = 5 + +:$ f(b) + :a = 10 + +|{f.a} = 2 diff --git a/test/tests/return children.ans b/test/tests/return children.ans new file mode 100644 index 0000000..5e93338 --- /dev/null +++ b/test/tests/return children.ans @@ -0,0 +1,13 @@ +:$ fn + :i=0 + @ + i=50 + i + +| {fn!} = 50 + +:$ g + @ + @3 + +| {g!} = 3 diff --git a/test/tests/tag operator.ans b/test/tests/tag operator.ans new file mode 100644 index 0000000..5dada34 --- /dev/null +++ b/test/tests/tag operator.ans @@ -0,0 +1,7 @@ +:$ f + @"b" + +|a {5 # |{f!}} c + +2:2 # + |a {5 # |{f!}} c diff --git a/test/tests/text buffer with tags.ans b/test/tests/text buffer with tags.ans new file mode 100644 index 0000000..4fce653 --- /dev/null +++ b/test/tests/text buffer with tags.ans @@ -0,0 +1,8 @@ +:$ f + 1 # | lol + + @2 # |d + +:a = |a {f!} {3#|t} b + +@a diff --git a/test/tests/text buffer.ans b/test/tests/text buffer.ans new file mode 100644 index 0000000..22cbdb3 --- /dev/null +++ b/test/tests/text buffer.ans @@ -0,0 +1,8 @@ +:$ f + |lol + + @|d + +:a = |a {f!} b + +@a diff --git a/test/tests/translate context.ans b/test/tests/translate context.ans new file mode 100644 index 0000000..b3c797f --- /dev/null +++ b/test/tests/translate context.ans @@ -0,0 +1,8 @@ +| Hello + +"source": "test/tests/translate context.ans:6:1" # + | Hello| -> | Bonjour + +| Hello + +| Hello diff --git a/test/tests/translate string.ans b/test/tests/translate string.ans new file mode 100644 index 0000000..8071453 --- /dev/null +++ b/test/tests/translate string.ans @@ -0,0 +1,5 @@ +|{%"Hello"} + +%"Hello" -> "Bonjour" + +|{%"Hello"} diff --git a/test/tests/translate text.ans b/test/tests/translate text.ans new file mode 100644 index 0000000..5f01701 --- /dev/null +++ b/test/tests/translate text.ans @@ -0,0 +1,5 @@ +| Hello + +| Hello| -> | Bonjour + +| Hello