aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-08-14 12:58:15 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commitcee06c2e498a2f8ab5a57b015922e4926e4d4676 (patch)
treef525862667ff548729bfdf855ca9f1483cf13fb9
parentspec/lang/fn (diff)
downloadalive-cee06c2e498a2f8ab5a57b015922e4926e4d4676.tar.gz
alive-cee06c2e498a2f8ab5a57b015922e4926e4d4676.zip
spec/lang/do
-rw-r--r--spec/lang/do_spec.moon33
-rw-r--r--spec/lang/fn_spec.moon6
-rw-r--r--spec/lang/literals_spec.moon10
3 files changed, 41 insertions, 8 deletions
diff --git a/spec/lang/do_spec.moon b/spec/lang/do_spec.moon
new file mode 100644
index 0000000..eecc326
--- /dev/null
+++ b/spec/lang/do_spec.moon
@@ -0,0 +1,33 @@
+import TestPilot from require 'spec.test_setup'
+import T, Struct, Array, Constant from require 'alv'
+
+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
+
+ 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
+
+ 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
+
+ it "passes through side-effects", ->
+ COPILOT.active_module\spit '
+ (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
+
diff --git a/spec/lang/fn_spec.moon b/spec/lang/fn_spec.moon
index 41a90d1..a95eac1 100644
--- a/spec/lang/fn_spec.moon
+++ b/spec/lang/fn_spec.moon
@@ -4,7 +4,7 @@ import T, Struct, Array, Constant from require 'alv'
describe "function", ->
COPILOT = TestPilot ''
- it 'returns constant results when constant', ->
+ it "returns constant results when constant", ->
COPILOT.active_module\spit '
(import* math)
@@ -17,7 +17,7 @@ describe "function", ->
result = assert COPILOT.active_module.root.result
assert.is.equal (Constant.num 5), result
- it 'checks argument arity when invoked', ->
+ it "checks argument arity when invoked", ->
COPILOT.active_module\spit '
([1]import* math)
@@ -40,7 +40,7 @@ describe "function", ->
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', ->
+ it "can be anonymously invoked", ->
COPILOT.active_module\spit '
([1]
([2]fn (a b) b)
diff --git a/spec/lang/literals_spec.moon b/spec/lang/literals_spec.moon
index 5bb0783..44d0d7d 100644
--- a/spec/lang/literals_spec.moon
+++ b/spec/lang/literals_spec.moon
@@ -13,21 +13,21 @@ describe "literal", ->
assert.is.true test.active_module.root\is_const!
scope = (assert test.active_module.root.result)\unwrap T.scope
- it 'string is parsed and returned correctly', ->
+ it "string is parsed and returned correctly", ->
assert.is.equal (Constant.str 'hello'), (scope\get 'str')\const!
- it 'number is parsed and returned correctly', ->
+ it "number is parsed and returned correctly", ->
assert.is.equal (Constant.num 2), (scope\get 'num')\const!
- it 'boolean is parsed and returned correctly', ->
+ it "boolean is parsed and returned correctly", ->
assert.is.equal (Constant.bool true), (scope\get 'bool')\const!
- it 'struct is parsed and returned correctly', ->
+ it "struct is parsed and returned correctly", ->
struct = (scope\get 'curl')\const!
assert.is.equal (Struct a: T.num, b: T.bool), struct.type
assert.is.same { a: 2, b: false }, struct!
- it 'array is parsed and returned correctly', ->
+ it "array is parsed and returned correctly", ->
array = (scope\get 'sqre')\const!
assert.is.equal (Array 4, T.num), array.type
assert.is.same {1, 2, 3, 4}, array!