diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-08-19 14:11:12 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:24:49 +0000 |
| commit | dea8c2a60f03d34cf0facd3d40b37b519f048126 (patch) | |
| tree | 12883cf84d158bdae1bacca1be9ba7d8713c9070 | |
| parent | add (failing) array spec (diff) | |
| download | alive-dea8c2a60f03d34cf0facd3d40b37b519f048126.tar.gz alive-dea8c2a60f03d34cf0facd3d40b37b519f048126.zip | |
add (failing) struct spec
| -rw-r--r-- | spec/lang/struct_spec.moon | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/lang/struct_spec.moon b/spec/lang/struct_spec.moon new file mode 100644 index 0000000..57c7e79 --- /dev/null +++ b/spec/lang/struct_spec.moon @@ -0,0 +1,51 @@ +import TestPilot from require 'spec.test_setup' +import T, Struct, Constant from require 'alv' + +describe "struct", -> + test = TestPilot '' + + ab = Struct { a: T.num, b: T.bool } + + describe "(set)", -> + it "can update values", -> + rt = COPILOT\eval_once '(set (struct "a" 1 "b" false) "a" 2)' + assert.is.true rt\is_const! + assert.is.equal ab\mk_const({ a: 2, b: false }), rt.result + + it "cannot add members", -> + err = assert.has.error -> COPILOT\eval_once '(set (struct "a" 1) "b" 2)' + assert.matches "argument error: TBD", err + + it "checks value type", -> + err = assert.has.error -> COPILOT\eval_once '(set (struct "a" 1) "a" "str")' + assert.matches "argument error: TBD", err + + describe "(get)", -> + it "can get values", -> + rt = COPILOT\eval_once '(get (struct "a" 1 "b" false) "a")' + assert.is.true rt\is_const! + assert.is.equal (Constant.num 1), rt.result + + it "checks keys", -> + err = assert.has.error -> COPILOT\eval_once '(get (struct "a" 1) "b")' + assert.matches "has no 'b' key", err + + describe "(insert)", -> + it "can add members", -> + rt = COPILOT\eval_once '(insert (struct "b" true) "a" 1)' + assert.is.true rt\is_const! + assert.is.equal ab\mk_const({ a: 1, b: true }), rt.result + + it "doesn't clobber existing members", -> + err = assert.has.error -> COPILOT\eval_once '(insert (struct "a" 1) "a" 2)' + assert.matches "TBD", err + + describe "(remove)", -> + it "can remove members", -> + rt = COPILOT\eval_once '(remove (struct "a" 1 "b" false "c" "abc") "c")' + assert.is.true rt\is_const! + assert.is.equal ab\mk_const({ a: 1, b: false }), rt.result + + it "checks keys", -> + err = assert.has.error -> COPILOT\eval_once '(remove (struct "a" 1) "b")' + assert.matches "has no 'b' key", err |
