aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-08-19 13:32:59 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commit9f6544e2d5a7ad153a03ee36254dccf4900377d2 (patch)
tree76f23b2681ffb067dbc06129f98a017a2d00a7e5
parentbugfixes with compound type comparisons (diff)
downloadalive-9f6544e2d5a7ad153a03ee36254dccf4900377d2.tar.gz
alive-9f6544e2d5a7ad153a03ee36254dccf4900377d2.zip
add TestPilot:eval_once
-rw-r--r--spec/lang/do_spec.moon28
-rw-r--r--spec/lang/fn_spec.moon22
-rw-r--r--spec/lang/literals_spec.moon6
-rw-r--r--spec/test_setup.moon5
4 files changed, 28 insertions, 33 deletions
diff --git a/spec/lang/do_spec.moon b/spec/lang/do_spec.moon
index eecc326..67b7b33 100644
--- a/spec/lang/do_spec.moon
+++ b/spec/lang/do_spec.moon
@@ -5,29 +5,25 @@ describe "do", ->
COPILOT = TestPilot ''
it "can be empty", ->
- COPILOT.active_module\spit '(do)'
- COPILOT\tick!
- assert.is.true COPILOT.active_module.root\is_const!
- assert.is.nil COPILOT.active_module.root.result
+ rt = COPILOT\eval_once '(do)'
+ assert.is.true rt\is_const!
+ assert.is.nil rt.result
it "returns the last result, if any", ->
- COPILOT.active_module\spit '(do 1 2 3)'
- COPILOT\tick!
- assert.is.true COPILOT.active_module.root\is_const!
- assert.is.equal (Constant.num 3), COPILOT.active_module.root.result
+ rt = COPILOT\eval_once '(do 1 2 3)'
+ assert.is.true rt\is_const!
+ assert.is.equal (Constant.num 3), rt.result
- COPILOT.active_module\spit '(do 1 2 (trace 3))'
- COPILOT\tick!
- assert.is.true COPILOT.active_module.root\is_const!
- assert.is.nil COPILOT.active_module.root.result
+ rt = COPILOT\eval_once '(do 1 2 (trace 3))'
+ assert.is.true rt\is_const!
+ assert.is.nil rt.result
it "passes through side-effects", ->
- COPILOT.active_module\spit '
+ rt = COPILOT\eval_once '
(import* time)
(do
(every 0.5 "bang! side-effect")
3)'
- COPILOT\tick!
- assert.is.false COPILOT.active_module.root\is_const!
- assert.is.equal (Constant.num 3), COPILOT.active_module.root.result
+ assert.is.false rt\is_const!
+ assert.is.equal (Constant.num 3), rt.result
diff --git a/spec/lang/fn_spec.moon b/spec/lang/fn_spec.moon
index a95eac1..3686c91 100644
--- a/spec/lang/fn_spec.moon
+++ b/spec/lang/fn_spec.moon
@@ -5,53 +5,47 @@ describe "function", ->
COPILOT = TestPilot ''
it "returns constant results when constant", ->
- COPILOT.active_module\spit '
+ rt = COPILOT\eval_once '
(import* math)
(defn my-plus (a b)
(+ a b))
(my-plus 2 3)'
- COPILOT\tick!
- assert.is.true COPILOT.active_module.root\is_const!
- result = assert COPILOT.active_module.root.result
- assert.is.equal (Constant.num 5), result
+ assert.is.true rt\is_const!
+ assert.is.equal (Constant.num 5), rt.result
it "checks argument arity when invoked", ->
- COPILOT.active_module\spit '
+ err = assert.has.error -> COPILOT\eval_once '
([1]import* math)
([2]defn my-plus (a b)
([4]+ a b))
([3]my-plus 2)'
- err = assert.has.error COPILOT\tick
assert.matches "argument error: expected 2 arguments, found 1", err
assert.matches "while invoking function 'my%-plus' at %[3%]", err
- COPILOT.active_module\spit '
+ err = assert.has.error -> COPILOT\eval_once '
([1]import* math)
([2]defn my-plus (a b)
([4]+ a b))
([3]my-plus 2 3 4)'
- err = assert.has.error COPILOT\tick
assert.matches "argument error: expected 2 arguments, found 3", err
assert.matches "while invoking function 'my%-plus' at %[3%]", err
it "can be anonymously invoked", ->
- COPILOT.active_module\spit '
+ rt = COPILOT\eval_once '
([1]
([2]fn (a b) b)
3 4)'
- COPILOT\tick!
- assert.is.equal (Constant.num 4), COPILOT.active_module.root\const!
+ assert.is.equal (Constant.num 4), rt\const!
- COPILOT.active_module\spit '
+ err = assert.has.error -> COPILOT\eval_once '
([1]
([2]fn (a b) b)
3)'
- err = assert.has.error COPILOT\tick
assert.matches "argument error: expected 2 arguments, found 1", err
assert.matches "while invoking function %(unnamed%) at %[1%]", err
diff --git a/spec/lang/literals_spec.moon b/spec/lang/literals_spec.moon
index 44d0d7d..3db010d 100644
--- a/spec/lang/literals_spec.moon
+++ b/spec/lang/literals_spec.moon
@@ -2,7 +2,7 @@ import TestPilot from require 'spec.test_setup'
import T, Struct, Array, Constant from require 'alv'
describe "literal", ->
- test = TestPilot '
+ TestPilot '
(def str "hello"
num 2
bool true
@@ -10,8 +10,8 @@ describe "literal", ->
sqre ([7]array 1 2 3 4))
(export*)'
- assert.is.true test.active_module.root\is_const!
- scope = (assert test.active_module.root.result)\unwrap T.scope
+ assert.is.true COPILOT.active_module.root\is_const!
+ scope = (assert COPILOT.active_module.root.result)\unwrap T.scope
it "string is parsed and returned correctly", ->
assert.is.equal (Constant.str 'hello'), (scope\get 'str')\const!
diff --git a/spec/test_setup.moon b/spec/test_setup.moon
index 965b2e7..2bcd9df 100644
--- a/spec/test_setup.moon
+++ b/spec/test_setup.moon
@@ -32,6 +32,11 @@ class TestPilot extends Copilot
end_eval: => @active_module.registry\end_eval!
next_tick: => @T += 1
+ eval_once: (code) =>
+ @active_module\spit code
+ @tick!
+ @active_module.root
+
--- poll for changes and tick.
tick: =>
return unless @last_modules.__root