From b3aad8ea771c4b73137086b20fd008513f463e7d Mon Sep 17 00:00:00 2001 From: s-ol Date: Fri, 14 Aug 2020 12:23:21 +0200 Subject: start working on language spec --- spec/lang/literals_spec.moon | 33 +++++++++++++++++++++++++++++++++ spec/test_setup.moon | 26 ++++++++++++++++++++------ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 spec/lang/literals_spec.moon 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 -- cgit v1.2.3