aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2022-10-20 11:20:46 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commit56bcabd974c0c0e34fb76d653e927668aaccbdb0 (patch)
treee8458a58b4edf72e6a7e59edccdaaaf9ed7198ab /spec/lib
parentbuiltins: test def, use, export, export* (diff)
downloadalive-56bcabd974c0c0e34fb76d653e927668aaccbdb0.tar.gz
alive-56bcabd974c0c0e34fb76d653e927668aaccbdb0.zip
lib: add <,<=,>,>= to logic, add tests
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/logic_spec.moon90
1 files changed, 89 insertions, 1 deletions
diff --git a/spec/lib/logic_spec.moon b/spec/lib/logic_spec.moon
index f3d0610..8e79cbd 100644
--- a/spec/lib/logic_spec.moon
+++ b/spec/lib/logic_spec.moon
@@ -2,7 +2,7 @@ import TestPilot from require 'spec.test_setup'
import T, Array, Constant from require 'alv'
describe "logic", ->
- test = TestPilot '', '(import* logic)\n'
+ test = TestPilot '', '(import* testing logic)\n'
TRUE = T.bool\mk_const true
FALSE = T.bool\mk_const false
@@ -262,3 +262,91 @@ describe "logic", ->
with COPILOT\eval_once '(and 1 1 1)'
assert.is.true \is_const!
assert.is.equal TRUE, .result
+
+ describe "<", ->
+ it "is aliased as asc?", -> COPILOT\eval_once '
+ (expect= < asc?)
+ '
+
+ it "compares numbers as expected", -> COPILOT\eval_once '
+ (assert (< -2 5))
+ (assert (not (< 3 1)))
+ (assert (not (< 1 1)))
+ '
+
+ it "can handle multiple arguments", -> COPILOT\eval_once '
+ (assert (< 1 2 3))
+ (assert (not (< 2 3.5 3 4)))
+ (assert (not (< 3 2 1)))
+ '
+
+ describe "<=", ->
+ it "compares numbers as expected", -> COPILOT\eval_once '
+ (assert (<= 1 1))
+ (assert (<= -2 2))
+ (assert (not (<= 3 2)))
+ '
+
+ it "can handle multiple arguments", -> COPILOT\eval_once '
+ (assert (<= 1 2 3))
+ (assert (<= 1 2 2 3))
+ (assert (not (<= 2 3 2.5 4)))
+ (assert (not (<= 3 2 2 1)))
+ '
+
+ describe ">", ->
+ it "is aliased as desc?", -> COPILOT\eval_once '
+ (expect= > desc?)
+ '
+
+ it "compares numbers as expected", -> COPILOT\eval_once '
+ (assert (> 3 1))
+ (assert (not (> -2 5)))
+ (assert (not (> 1 1)))
+ '
+
+ it "can handle multiple arguments", -> COPILOT\eval_once '
+ (assert (> 3 2 1))
+ (assert (not (> 5 4 3 3.5 2)))
+ (assert (not (> 1 2 3)))
+ '
+
+ describe ">=", ->
+ it "compares numbers as expected", -> COPILOT\eval_once '
+ (assert (>= 1 1))
+ (assert (>= 5 1))
+ (assert (not (>= 2 3)))
+ '
+
+ it "can handle multiple arguments", -> COPILOT\eval_once '
+ (assert (>= 3 2 1))
+ (assert (>= 3 2 2 1))
+ (assert (not (>= 5 4 3 3 3.5 2)))
+ (assert (not (>= 1 2 2 3)))
+ '
+
+ describe "<, <=, >, >=", ->
+ each = (fn) ->
+ fn '<'
+ fn '<='
+ fn '>'
+ fn '>='
+
+ it "need at least two arguments", ->
+ each =>
+ err = assert.has.error -> COPILOT\eval_once "(#{@})"
+ assert.matches "couldn't match arguments", err
+
+ err = assert.has.error -> COPILOT\eval_once "(#{@} 1)"
+ assert.matches "couldn't match arguments", err
+
+ it "only work on numbers", ->
+ each =>
+ err = assert.has.error -> COPILOT\eval_once "(#{@} 1 'b')"
+ assert.matches "couldn't match arguments", err
+
+ err = assert.has.error -> COPILOT\eval_once "(#{@} 'c' 'd')"
+ assert.matches "couldn't match arguments", err
+
+ err = assert.has.error -> COPILOT\eval_once "(#{@} true 3)"
+ assert.matches "couldn't match arguments", err