diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-08-14 10:23:21 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:24:49 +0000 |
| commit | 77ce73dbee8f67d7fc204c5d57b5392a931c4724 (patch) | |
| tree | 532261b6e029744ca4f1e04b3e7d869e096dcd06 | |
| parent | make error highest logging prio (diff) | |
| download | alive-77ce73dbee8f67d7fc204c5d57b5392a931c4724.tar.gz alive-77ce73dbee8f67d7fc204c5d57b5392a931c4724.zip | |
start working on language spec
| -rw-r--r-- | spec/lang/literals_spec.moon | 33 | ||||
| -rw-r--r-- | spec/test_setup.moon | 26 |
2 files changed, 53 insertions, 6 deletions
diff --git a/spec/lang/literals_spec.moon b/spec/lang/literals_spec.moon new file mode 100644 index 0000000..b0c869d --- /dev/null +++ b/spec/lang/literals_spec.moon @@ -0,0 +1,33 @@ +import TestPilot from require 'spec.test_setup' +import T, Struct, Array, Constant from require 'alv' + +describe "literal", -> + test = TestPilot ' + (def str "hello" + num 2 + bool true + curl ([5]struct "a" 2 "b" false) + sqre ([7]array 1 2 3 4)) + (export*)' + + assert.is.true test.active_module.root\is_const! + scope = (assert test.active_module.root.result)\unwrap T.scope + + it 'string', -> + assert.is.equal (Constant.str 'hello'), (scope\get 'str')\const! + + it 'number', -> + assert.is.equal (Constant.num 2), (scope\get 'num')\const! + + it 'boolean', -> + assert.is.equal (Constant.bool true), (scope\get 'bool')\const! + + it 'structs', -> + 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 'arrays', -> + array = (scope\get 'sqre')\const! + assert.is.equal (Array 4, T.num), array.type + assert.is.same {1, 2, 3, 4}, array! diff --git a/spec/test_setup.moon b/spec/test_setup.moon index 92bb61e..c25cb14 100644 --- a/spec/test_setup.moon +++ b/spec/test_setup.moon @@ -1,20 +1,34 @@ import Constant, Scope, Op, Tag from require 'alv' import Copilot from require 'alv.copilot.base' -import Module from require 'alv.module' +import Module, StringModule from require 'alv.module' import Logger from require 'alv.logger' -Logger\init 'silent' +import Error from require 'alv.error' +import RTNode from require 'alv.rtnode' +Logger\init 'error' class TestPilot extends Copilot new: (code) => - @T = 0 - @active_module = Module! + super! + + if code + @active_module = StringModule 'main', code + @last_modules.__root = @active_module + @tick! + else + @active_module = Module! + @last_modules.__root = @active_module begin_eval: => @active_module.registry\begin_eval! end_eval: => @active_module.registry\end_eval! next_tick: => @T += 1 - require: => - error "not implemented" + require: (name) => + Error.wrap "loading module '#{name}'", -> + ok, lua = pcall require, "alv-lib.#{name}" + if ok + RTNode result: Constant.wrap lua + else + error Error 'import', "module not found" export COPILOT |
