aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/core/cell_spec.moon (renamed from spec/cell_spec.moon)0
-rw-r--r--spec/core/parsing_spec.moon (renamed from spec/parsing_spec.moon)0
-rw-r--r--spec/core/registry_spec.moon (renamed from spec/registry_spec.moon)0
-rw-r--r--spec/core/scope_spec.moon (renamed from spec/scope_spec.moon)0
-rw-r--r--spec/core/tag_spec.moon100
-rw-r--r--spec/core/value_spec.moon (renamed from spec/value_spec.moon)11
6 files changed, 111 insertions, 0 deletions
diff --git a/spec/cell_spec.moon b/spec/core/cell_spec.moon
index fcf9861..fcf9861 100644
--- a/spec/cell_spec.moon
+++ b/spec/core/cell_spec.moon
diff --git a/spec/parsing_spec.moon b/spec/core/parsing_spec.moon
index ddf760f..ddf760f 100644
--- a/spec/parsing_spec.moon
+++ b/spec/core/parsing_spec.moon
diff --git a/spec/registry_spec.moon b/spec/core/registry_spec.moon
index 6fe2e3a..6fe2e3a 100644
--- a/spec/registry_spec.moon
+++ b/spec/core/registry_spec.moon
diff --git a/spec/scope_spec.moon b/spec/core/scope_spec.moon
index 471bbce..471bbce 100644
--- a/spec/scope_spec.moon
+++ b/spec/core/scope_spec.moon
diff --git a/spec/core/tag_spec.moon b/spec/core/tag_spec.moon
new file mode 100644
index 0000000..7855fd6
--- /dev/null
+++ b/spec/core/tag_spec.moon
@@ -0,0 +1,100 @@
+import Tag from require 'core.tag'
+import Registry from require 'core.registry'
+import Logger from require 'logger'
+Logger.init 'silent'
+
+with_reg = (fn) ->
+ registry = Registry!
+ fn = registry\wrap_eval fn
+ fn, registry
+
+do_reg = (fn) ->
+ fn, reg = with_reg fn
+ fn!
+ reg
+
+describe 'Tag', ->
+ describe 'should be constructable', ->
+ it 'by parsing', ->
+ tag = Tag\parse '2'
+ assert tag
+ assert.is.equal 2, tag.value
+ assert.is.equal '[2]', tag\stringify!
+ assert.is.equal '2', tostring tag
+
+ it 'as blank Tags', ->
+ tag = Tag\blank!
+ assert tag
+ assert.is.nil tag.value
+ assert.is.equal '', tag\stringify!
+ assert.is.equal '?', tostring tag
+
+ describe 'should be clonable', ->
+ do_asserts = (tag, expect) ->
+ assert tag
+ assert.is.nil tag.value
+ assert.is.equal expect, tostring tag
+ assert.has.error tag\stringify
+
+ it 'from parsed tags', with_reg ->
+ parent = Tag\parse '1'
+ original = Tag\parse '2'
+ tag = original\clone parent
+ do_asserts tag, '1.2'
+
+ it 'but not from blank tags', with_reg ->
+ parent = Tag\parse '1'
+ original = Tag\blank!
+ tag = original\clone parent
+ do_asserts tag, '1.?'
+
+ it 'with blank parent', with_reg ->
+ parent = Tag\blank!
+ original = Tag\parse '2'
+ tag = original\clone parent
+ do_asserts tag, '?.2'
+
+ it 'completely blank', with_reg ->
+ parent = Tag\blank!
+ original = Tag\blank!
+ tag = original\clone parent
+ do_asserts tag, '?.?'
+
+ describe 'should be set-able', ->
+ it 'only if blank', with_reg ->
+ tag = Tag\parse '42'
+ assert.has.error -> tag\set 43
+
+ clone = tag\clone Tag\parse '3'
+ assert.has.error -> clone\set 42
+
+ clone = tag\clone Tag\blank!
+ assert.has.error -> clone\set 42
+
+ it 'and stores the value', with_reg ->
+ blank = Tag\blank!
+ blank\set 12
+
+ assert.is.equal blank.value, 12
+
+ it 'sets the original if cloned', with_reg ->
+ original = Tag\blank!
+ parent = Tag\parse '7'
+
+ o_set = spy.on original, 'set'
+ p_set = spy.on parent, 'set'
+
+ clone = original\clone parent
+ clone\set 11
+
+ assert.spy(o_set).was_called_with (match.is_ref original), 11
+ assert.spy(p_set).was_not_called!
+
+ assert.is.equal original.value, 11
+
+ it 'requires the parent to be registered if cloned', with_reg ->
+ original = Tag\blank!
+ parent = Tag\blank!
+
+ clone = original\clone parent
+ assert.has.error -> clone\set 11
diff --git a/spec/value_spec.moon b/spec/core/value_spec.moon
index bc68c5b..cda7123 100644
--- a/spec/value_spec.moon
+++ b/spec/core/value_spec.moon
@@ -66,6 +66,17 @@ describe 'Value', ->
assert.has_error -> (Value.str 'hi')\unwrap 'num'
assert.has_error -> (Value.sym 'hi')\unwrap 'str'
+ test 'with __call shorthand', ->
+ assert.is.equal 3.14, (Value.num 3.14)!
+ assert.is.equal 'hi', (Value.str 'hi')!
+ assert.is.equal 'hi', (Value.sym 'hi')!
+ assert.is.equal 3.14, (Value.num 3.14) 'num'
+ assert.is.equal 'hi', (Value.str 'hi') 'str'
+ assert.is.equal 'hi', (Value.sym 'hi') 'sym'
+ assert.has_error -> (Value.num 3.14) 'sym'
+ assert.has_error -> (Value.str 'hi') 'num'
+ assert.has_error -> (Value.sym 'hi') 'str'
+
describe 'checks equality', ->
test 'using the type', ->
val = Value 'num', 3