From 409a2e7095b61f94535a66b53703650bea6aa635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Sun, 31 Dec 2023 14:30:14 +0100 Subject: [PATCH] Firth test batch and associated fixes --- anselme/stdlib/conditionals.lua | 10 ++- test/results/checkpoint change.ans | 45 ++++++++++ test/results/checkpoint reached seen.ans | 9 ++ ...nction separate variable from variants.ans | 4 +- test/results/paragraph run force.ans | 17 ++++ test/results/paragraph run from.ans | 17 ++++ test/results/paragraph run.ans | 17 ++++ test/results/paragraph.ans | 7 ++ test/results/resume from nested paragraph.ans | 38 ++++++++ .../resume from paragraph restore tags.ans | 21 +++++ ...sume from paragraph with nested choice.ans | 85 ++++++++++++++++++ ...e from paragraph with nested condition.ans | 13 +++ test/tests/checkpoint change.ans | 30 +++++++ test/tests/checkpoint reached seen.ans | 11 +++ test/tests/paragraph run force.ans | 14 +++ test/tests/paragraph run from.ans | 14 +++ test/tests/paragraph run.ans | 14 +++ test/tests/paragraph.ans | 4 + test/tests/resume from nested paragraph.ans | 26 ++++++ .../resume from paragraph restore tags.ans | 17 ++++ ...sume from paragraph with nested choice.ans | 87 +++++++++++++++++++ ...e from paragraph with nested condition.ans | 21 +++++ 22 files changed, 516 insertions(+), 5 deletions(-) create mode 100644 test/results/checkpoint change.ans create mode 100644 test/results/checkpoint reached seen.ans create mode 100644 test/results/paragraph run force.ans create mode 100644 test/results/paragraph run from.ans create mode 100644 test/results/paragraph run.ans create mode 100644 test/results/paragraph.ans create mode 100644 test/results/resume from nested paragraph.ans create mode 100644 test/results/resume from paragraph restore tags.ans create mode 100644 test/results/resume from paragraph with nested choice.ans create mode 100644 test/results/resume from paragraph with nested condition.ans create mode 100644 test/tests/checkpoint change.ans create mode 100644 test/tests/checkpoint reached seen.ans create mode 100644 test/tests/paragraph run force.ans create mode 100644 test/tests/paragraph run from.ans create mode 100644 test/tests/paragraph run.ans create mode 100644 test/tests/paragraph.ans create mode 100644 test/tests/resume from nested paragraph.ans create mode 100644 test/tests/resume from paragraph restore tags.ans create mode 100644 test/tests/resume from paragraph with nested choice.ans create mode 100644 test/tests/resume from paragraph with nested condition.ans diff --git a/anselme/stdlib/conditionals.lua b/anselme/stdlib/conditionals.lua index d3a673a..459fc6f 100644 --- a/anselme/stdlib/conditionals.lua +++ b/anselme/stdlib/conditionals.lua @@ -1,6 +1,8 @@ local ast = require("anselme.ast") local ArgumentTuple, Nil, Boolean, Identifier, Return = ast.ArgumentTuple, ast.Nil, ast.Boolean, ast.Identifier, ast.Return +local resume_manager = require("anselme.state.resume_manager") + local if_identifier = Identifier:new("_if_status") local if_symbol = if_identifier:to_symbol() @@ -20,7 +22,7 @@ return { { "_~_", "(condition, expression)", function(state, condition, expression) ensure_if_variable(state) - if condition:truthy() then + if condition:truthy() or resume_manager:resuming(state) then--expression:contains_current_resume_target(state) then TODO fix set_if_variable(state, true) return expression:call(state, ArgumentTuple:new()) else @@ -33,11 +35,11 @@ return { "~_", "(expression)", function(state, expression) ensure_if_variable(state) - if last_if_success(state) then - return Nil:new() - else + if not last_if_success(state) or resume_manager:resuming(state) then--expression:contains_current_resume_target(state) then TODO fix set_if_variable(state, true) return expression:call(state, ArgumentTuple:new()) + else + return Nil:new() end end }, diff --git a/test/results/checkpoint change.ans b/test/results/checkpoint change.ans new file mode 100644 index 0000000..eeb3b0c --- /dev/null +++ b/test/results/checkpoint change.ans @@ -0,0 +1,45 @@ +--# run #-- +--- text --- +| {}"From start:" | +| {}"x" | +--- text --- +| {}"d" | +--- text --- +| {}"From p checkpoint:" | +| {}"a" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- text --- +| {}"From q checkpoint:" | +| {}"b" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- text --- +| {}"From q checkpoint again:" | +| {}"b" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- text --- +| {}"Go to p again by setting checkpoint manually:" | +| {}"a" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- text --- +| {}"From q again:" | +| {}"b" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#q, "f.reached":*{#p:1, #q:2}, "f.run":6} \ No newline at end of file diff --git a/test/results/checkpoint reached seen.ans b/test/results/checkpoint reached seen.ans new file mode 100644 index 0000000..b9fb32e --- /dev/null +++ b/test/results/checkpoint reached seen.ans @@ -0,0 +1,9 @@ +--# run #-- +--- text --- +| {}"Seen: " {}"2" {}"" | +--- text --- +| {}"Reached: " {}"1" {}"" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#p, "f.reached":*{#p:1, #s:2}, "f.run":2} \ 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 index 334c360..3e5b073 100644 --- a/test/results/function separate variable from variants.ans +++ b/test/results/function separate variable from variants.ans @@ -1,6 +1,8 @@ --# 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: +can't call overload overload<($(s::($(x) type(x) == t), k::($(x) )) = val; _), ($(s::($(x) type(x) == t), k::($(x) )) _), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) )>: no function match (overload<($(b) _), ($(x) _), ($() _)>, "a"), possible functions were: + • (s::($(x) type(x) == t), k::($(x) )) = val: expected 3 arguments, received 2 + • (s::($(x) type(x) == t), k::($(x) )): type check failure for parameter s in function (s::($(x) type(x) == t), k::($(x) )) • (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) )) diff --git a/test/results/paragraph run force.ans b/test/results/paragraph run force.ans new file mode 100644 index 0000000..81fd9b4 --- /dev/null +++ b/test/results/paragraph run force.ans @@ -0,0 +1,17 @@ +--# run #-- +--- text --- +| {}"Force run checkpoint:" | +| {}"a" | +| {}"b" | +--- text --- +| {}"From checkpoint:" | +| {}"a" | +| {}"b" | +--- text --- +| {}"Force no checkpoint:" | +| {}"x" | +| {}"b" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#p, "f.reached":*{#p:1}, "f.run":3} \ No newline at end of file diff --git a/test/results/paragraph run from.ans b/test/results/paragraph run from.ans new file mode 100644 index 0000000..27e6115 --- /dev/null +++ b/test/results/paragraph run from.ans @@ -0,0 +1,17 @@ +--# run #-- +--- text --- +| {}"Force run from checkpoint:" | +| {}"a" | +| {}"b" | +--- text --- +| {}"From checkpoint:" | +| {}"a" | +| {}"b" | +--- text --- +| {}"Force no checkpoint:" | +| {}"x" | +| {}"b" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#p, "f.reached":*{#p:1}, "f.run":3} \ No newline at end of file diff --git a/test/results/paragraph run.ans b/test/results/paragraph run.ans new file mode 100644 index 0000000..a2ab961 --- /dev/null +++ b/test/results/paragraph run.ans @@ -0,0 +1,17 @@ +--# run #-- +--- text --- +| {}"No checkpoint:" | +| {}"x" | +| {}"b" | +--- text --- +| {}"From checkpoint:" | +| {}"a" | +| {}"b" | +--- text --- +| {}"Force no checkpoint:" | +| {}"x" | +| {}"b" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#p, "f.reached":*{#p:2}, "f.run":3} \ No newline at end of file diff --git a/test/results/paragraph.ans b/test/results/paragraph.ans new file mode 100644 index 0000000..859584d --- /dev/null +++ b/test/results/paragraph.ans @@ -0,0 +1,7 @@ +--# run #-- +--- text --- +| {}"b" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/resume from nested paragraph.ans b/test/results/resume from nested paragraph.ans new file mode 100644 index 0000000..196b9d8 --- /dev/null +++ b/test/results/resume from nested paragraph.ans @@ -0,0 +1,38 @@ +--# run #-- +--- text --- +| {}"From start:" | +| {}"x" | +--- text --- +| {}"d" | +--- text --- +| {}"From p checkpoint:" | +| {}"a" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- text --- +| {}"From q checkpoint:" | +| {}"b" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- text --- +| {}"From q checkpoint again:" | +| {}"b" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- text --- +| {}"Force p checkpoint:" | +| {}"a" | +--- text --- +| {}"c" | +--- text --- +| {}"d" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#q, "f.reached":*{#p:1, #q:2}, "f.run":5} \ No newline at end of file diff --git a/test/results/resume from paragraph restore tags.ans b/test/results/resume from paragraph restore tags.ans new file mode 100644 index 0000000..73dede2 --- /dev/null +++ b/test/results/resume from paragraph restore tags.ans @@ -0,0 +1,21 @@ +--# run #-- +--- text --- +| {"a":"a"}"a" | +--- text --- +| {"a":"a", "b":"b", "x":"x"}"c" | +--- text --- +| {"a":"a"}"d" | +--- text --- +| {}"e" | +--- text --- +| {"a":"a", "b":"b", "c":"c", "x":"x"}"b" | +--- text --- +| {"a":"a", "b":"b", "x":"x"}"c" | +--- text --- +| {"a":"a"}"d" | +--- text --- +| {}"e" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#p, "f.reached":*{#p:1}, "f.run":2} \ No newline at end of file diff --git a/test/results/resume from paragraph with nested choice.ans b/test/results/resume from paragraph with nested choice.ans new file mode 100644 index 0000000..04077ae --- /dev/null +++ b/test/results/resume from paragraph with nested choice.ans @@ -0,0 +1,85 @@ +--# run #-- +--- text --- +| {}"f:" | +--- choice --- + > | {}"a" | +=> | {}"b" | +--- text --- +| {}"-> b" | +--- choice --- +=> | {}"c" | +--- text --- +| {}"-> c" | +| {}"f from #p:" | +--- choice --- + > | {}"aa" | +=> | {}"ab" | +--- text --- +| {}"-> ab" | +--- text --- +| {}"g:" | +--- choice --- + > | {}"a" | +=> | {}"b" | +--- text --- +| {}"-> b" | +| {}"autoflush" | +--- choice --- +=> | {}"c" | +--- text --- +| {}"-> c" | +| {}"g from #p:" | +--- choice --- + > | {}"aa" | +=> | {}"ab" | +--- text --- +| {}"-> ab" | +| {}"autoflush" | +--- choice --- +=> | {}"c" | +--- text --- +| {}"-> c" | +--- text --- +| {}"h:" | +--- choice --- +=> | {}"a" | + > | {}"b" | + > | {}"c" | +--- text --- +| {}"-> a" | +--- choice --- +=> | {}"aa" | + > | {}"ab" | +--- text --- +| {}"-> aa" | +| {}"h from #p:" | +--- choice --- +=> | {}"aa" | + > | {}"ab" | + > | {}"c" | +--- text --- +| {}"-> aa" | +--- text --- +| {}"i:" | +--- choice --- +=> | {}"a" | + > | {}"b" | + > | {}"c" | +--- text --- +| {}"-> a" | +--- choice --- +=> | {}"aa" | + > | {}"ab" | +--- text --- +| {}"-> aa" | +| {}"i from #p:" | +--- choice --- +=> | {}"aa" | + > | {}"ab" | + > | {}"c" | +--- text --- +| {}"-> aa" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#p, "f.run":2, "g.checkpoint":#p, "g.run":2, "h.checkpoint":#p, "h.reached":*{#p:1}, "h.run":2, "i.checkpoint":#p, "i.reached":*{#p:1}, "i.run":2} \ No newline at end of file diff --git a/test/results/resume from paragraph with nested condition.ans b/test/results/resume from paragraph with nested condition.ans new file mode 100644 index 0000000..a973669 --- /dev/null +++ b/test/results/resume from paragraph with nested condition.ans @@ -0,0 +1,13 @@ +--# run #-- +--- text --- +| {}"x" | +--- text --- +| {}"x" | +--- text --- +| {}"y" | +--- text --- +| {}"x" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#p, "f.reached":*{#p:1}, "f.run":2, "g.checkpoint":#p, "g.run":2} \ No newline at end of file diff --git a/test/tests/checkpoint change.ans b/test/tests/checkpoint change.ans new file mode 100644 index 0000000..1c0b84e --- /dev/null +++ b/test/tests/checkpoint change.ans @@ -0,0 +1,30 @@ +:f = "f"!script($_) + |x + #p!checkpoint($_) + |a + + #q!checkpoint($_) + |b + + |c + + |d + +|From start: +f! + +|From p checkpoint: +f! + +|From q checkpoint: +f! + +|From q checkpoint again: +f! + +|Go to p again by setting checkpoint manually: +f.current checkpoint = #p +f! + +|From q again: +f! diff --git a/test/tests/checkpoint reached seen.ans b/test/tests/checkpoint reached seen.ans new file mode 100644 index 0000000..8eea78f --- /dev/null +++ b/test/tests/checkpoint reached seen.ans @@ -0,0 +1,11 @@ +:f = "f"!script($_) + #p!checkpoint + #s!check + +f! + +f! + +|Seen: {f.reached(#s)} + +|Reached: {f.reached(#p)} diff --git a/test/tests/paragraph run force.ans b/test/tests/paragraph run force.ans new file mode 100644 index 0000000..971ca03 --- /dev/null +++ b/test/tests/paragraph run force.ans @@ -0,0 +1,14 @@ +:f = "f"!script($_) + |x + #p!checkpoint($_) + |a + |b + +|Force run checkpoint: +f!from(#p) + +|From checkpoint: +f! + +|Force no checkpoint: +f!from() diff --git a/test/tests/paragraph run from.ans b/test/tests/paragraph run from.ans new file mode 100644 index 0000000..0c1f85e --- /dev/null +++ b/test/tests/paragraph run from.ans @@ -0,0 +1,14 @@ +:f = "f"!script($_) + |x + #p!checkpoint($_) + |a + |b + +|Force run from checkpoint: +f!from(#p) + +|From checkpoint: +f! + +|Force no checkpoint: +f!from() diff --git a/test/tests/paragraph run.ans b/test/tests/paragraph run.ans new file mode 100644 index 0000000..8542159 --- /dev/null +++ b/test/tests/paragraph run.ans @@ -0,0 +1,14 @@ +: f = "f"!script($_) + |x + #p!checkpoint($_) + |a + |b + +|No checkpoint: +f! + +|From checkpoint: +f! + +|Force no checkpoint: +f!from() diff --git a/test/tests/paragraph.ans b/test/tests/paragraph.ans new file mode 100644 index 0000000..adc9a8b --- /dev/null +++ b/test/tests/paragraph.ans @@ -0,0 +1,4 @@ +:f = "g"!script($_) + #p!checkpoint($_) + |a +|b \ No newline at end of file diff --git a/test/tests/resume from nested paragraph.ans b/test/tests/resume from nested paragraph.ans new file mode 100644 index 0000000..1c9aa86 --- /dev/null +++ b/test/tests/resume from nested paragraph.ans @@ -0,0 +1,26 @@ +:f = "f"!script($_) + |x + #p!checkpoint($_) + |a + + #q!checkpoint($_) + |b + + |c + + |d + +|From start: +f! + +|From p checkpoint: +f! + +|From q checkpoint: +f! + +|From q checkpoint again: +f! + +|Force p checkpoint: +f!from(#p) diff --git a/test/tests/resume from paragraph restore tags.ans b/test/tests/resume from paragraph restore tags.ans new file mode 100644 index 0000000..e854f01 --- /dev/null +++ b/test/tests/resume from paragraph restore tags.ans @@ -0,0 +1,17 @@ +:f = "f"!script($_) + "a":"a" # + |a + 1 ~ "x":"x" # + "b":"b" # + #p!checkpoint($_) + "c":"c"# |b + + |c + + |d + + |e + +f! + +f! diff --git a/test/tests/resume from paragraph with nested choice.ans b/test/tests/resume from paragraph with nested choice.ans new file mode 100644 index 0000000..bee2729 --- /dev/null +++ b/test/tests/resume from paragraph with nested choice.ans @@ -0,0 +1,87 @@ +:@choice = 2 + +:f = "f"!script($_) + | a |> + |-> a + #p!checkpoint + | aa |> + |-> aa + | ab |> + |-> ab + | b |> + |-> b + choice = 2 + + | c |> + |-> c + choice=1 + +| f: +f! + +| f from #p: +f!from(#p) + +:g = "g"!script($_) + | a |> + |-> a + #p!checkpoint + | aa |> + |-> aa + | ab |> + |-> ab + | b |> + |-> b + choice = 2 + |autoflush + | c |> + |-> c + choice = 1 + +| g: +g! + +| g from #p: +g!from(#p) + +:h = "h"!script($_) + 1 ~ + | a |> + |-> a + #p!checkpoint + | aa |> + |-> aa + | ab |> + |-> ab + choice = 1 + | b |> + |-> b + | c |> + |-> c + choice = 1 + +| h: +h! + +| h from #p: +h!from(#p) + +:i = "i"!script($_) + | a |> + |-> a + #p!checkpoint + | aa |> + |-> aa + | ab |> + |-> ab + | b |> + |-> b + 1 ~ + | c |> + |-> c + +| i: +i! + +| i from #p: +i!from(#p) diff --git a/test/tests/resume from paragraph with nested condition.ans b/test/tests/resume from paragraph with nested condition.ans new file mode 100644 index 0000000..9cf1cce --- /dev/null +++ b/test/tests/resume from paragraph with nested condition.ans @@ -0,0 +1,21 @@ +:f = "f"!script($_) + 1 ~ + #p!checkpoint + |x + ~ + |y + +f! + +f!from(#p) + +:g = "g"!script($_) + () ~ + #p!checkpoint + |x + ~ + |y + +g! + +g!from(#p)