aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-11-13 17:13:47 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commit8e9815f30a89c1079d531272a4e51efe38178260 (patch)
tree5e39f62cc45c8cd3f7ee5a2384471987689bc843
parentfix bug in ! builtin (diff)
downloadalive-8e9815f30a89c1079d531272a4e51efe38178260.tar.gz
alive-8e9815f30a89c1079d531272a4e51efe38178260.zip
fix pretty-printing for "false" values
-rw-r--r--alv/result/base.moon2
-rw-r--r--spec/result/const_spec.moon5
-rw-r--r--spec/result/evt_spec.moon16
-rw-r--r--spec/result/sig_spec.moon5
-rw-r--r--spec/type_spec.moon2
5 files changed, 29 insertions, 1 deletions
diff --git a/alv/result/base.moon b/alv/result/base.moon
index a9a668d..d2865d2 100644
--- a/alv/result/base.moon
+++ b/alv/result/base.moon
@@ -27,7 +27,7 @@ class Result
-- @treturn Result
__tostring: =>
- if @value then
+ if @value != nil then
"<#{@type}#{@metatype} #{@type\pp @value}>"
else
"<#{@type}#{@metatype}>"
diff --git a/spec/result/const_spec.moon b/spec/result/const_spec.moon
index a6ab43e..3f31306 100644
--- a/spec/result/const_spec.moon
+++ b/spec/result/const_spec.moon
@@ -16,6 +16,11 @@ describe 'Constant', ->
assert.has.error -> Constant T.num
assert.has.no.error -> Constant T.bool, false
+ it 'stringifies well', ->
+ assert.is.equal "<num= 4>", tostring Constant.num 4
+ assert.is.equal "<bool= true>", tostring Constant.bool true
+ assert.is.equal "<bool= false>", tostring Constant.bool false
+
describe '.wrap', ->
it 'wraps numbers', ->
got = Constant.wrap 3
diff --git a/spec/result/evt_spec.moon b/spec/result/evt_spec.moon
index c9416db..46d4cec 100644
--- a/spec/result/evt_spec.moon
+++ b/spec/result/evt_spec.moon
@@ -5,6 +5,22 @@ import Op, Builtin from require 'alv.base'
setup do_setup
describe 'EvtStream', ->
+ it 'stringifies well', ->
+ number = EvtStream T.num
+ assert.is.equal "<num! nil>", tostring number
+
+ number\set 4
+ assert.is.equal "<num! 4>", tostring number
+
+ bool = EvtStream T.bool
+ bool\set true
+ assert.is.equal "<bool! true>", tostring bool
+
+ COPILOT\next_tick!
+
+ bool\set false
+ assert.is.equal "<bool! false>", tostring bool
+
describe ':unwrap', ->
it 'returns the set value', ->
stream = EvtStream T.num
diff --git a/spec/result/sig_spec.moon b/spec/result/sig_spec.moon
index 1a92bdc..65363bc 100644
--- a/spec/result/sig_spec.moon
+++ b/spec/result/sig_spec.moon
@@ -5,6 +5,11 @@ import Op, Builtin from require 'alv.base'
setup do_setup
describe 'SigStream', ->
+ it 'stringifies well', ->
+ assert.is.equal "<num~ 4>", tostring SigStream T.num, 4
+ assert.is.equal "<bool~ true>", tostring SigStream T.bool, true
+ assert.is.equal "<bool~ false>", tostring SigStream T.bool, false
+
describe ':unwrap', ->
it 'returns the raw value!', ->
assert.is.equal 3.14, (SigStream T.num, 3.14)\unwrap!
diff --git a/spec/type_spec.moon b/spec/type_spec.moon
index 0293385..727e90b 100644
--- a/spec/type_spec.moon
+++ b/spec/type_spec.moon
@@ -29,6 +29,8 @@ describe 'Primitive', ->
it ':pp pretty-prints values', ->
assert.is.equal 'true', bool\pp true
+ assert.is.equal 'false', bool\pp false
+ assert.is.equal 'nil', bool\pp nil
assert.is.equal '4.134', num\pp 4.134
assert.is.equal '"hello"', str\pp "hello"