From dab227b4da2744fd6d6d88424de42b3d254298b8 Mon Sep 17 00:00:00 2001 From: rhysd Date: Mon, 8 Jun 2015 15:53:30 +0900 Subject: [PATCH] add first spec --- .travis.yml | 1 + spec/.gitkeep | 0 spec/crisp/interpreter_spec.cr | 15 +++++++++++++++ spec/helper.cr | 5 +++++ src/crisp/interpreter.cr | 12 ++++++++++-- 5 files changed, 31 insertions(+), 2 deletions(-) delete mode 100644 spec/.gitkeep create mode 100644 spec/crisp/interpreter_spec.cr create mode 100644 spec/helper.cr diff --git a/.travis.yml b/.travis.yml index fa7a59b..5d2551e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,4 @@ install: | sudo apt-get install crystal script: - crystal build crisp.cr + - crystal spec diff --git a/spec/.gitkeep b/spec/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/crisp/interpreter_spec.cr b/spec/crisp/interpreter_spec.cr new file mode 100644 index 0000000..9c243f2 --- /dev/null +++ b/spec/crisp/interpreter_spec.cr @@ -0,0 +1,15 @@ +require "../helper" +require_crisp "interpreter" + +describe "Crisp::Interpreter" + describe "#eval_string" + it "evaluates string of Crisp expression" + i = Crisp::Interpreter.new + result = i.eval_string "(+ 1 2)" + result.should be_a(Crisp::Type) + unwrapped = result.unwrap + result.should be_a(Int32) + result.should eq(unwrapped, 3) + end + end +end diff --git a/spec/helper.cr b/spec/helper.cr new file mode 100644 index 0000000..f399963 --- /dev/null +++ b/spec/helper.cr @@ -0,0 +1,5 @@ +require "spec" + +macro require_crisp(module) + require "../../src/crisp/{{module}}" +end diff --git a/src/crisp/interpreter.cr b/src/crisp/interpreter.cr index ffea0f8..a77a7e5 100644 --- a/src/crisp/interpreter.cr +++ b/src/crisp/interpreter.cr @@ -46,7 +46,15 @@ module Crisp end def eval_string(str) - print(@evaluator.eval(read(str), @env)) + @evaluator.eval(read(str), @env) + end + + def eval(t : Crisp::Type) + @evaluator.eval(t, @env) + end + + def eval(val) + @evaluator.eval(Crisp::Type.new val, @env) end def run(filename = nil) @@ -57,7 +65,7 @@ module Crisp while line = Readline.readline("Crisp> ", true) begin - puts eval_string(line) + puts self.print(eval_string(line)) rescue e puts e.message end