瀏覽代碼

add first spec

master
rhysd 9 年之前
父節點
當前提交
dab227b4da
共有 5 個文件被更改,包括 31 次插入2 次删除
  1. +1
    -0
      .travis.yml
  2. +0
    -0
      spec/.gitkeep
  3. +15
    -0
      spec/crisp/interpreter_spec.cr
  4. +5
    -0
      spec/helper.cr
  5. +10
    -2
      src/crisp/interpreter.cr

+ 1
- 0
.travis.yml 查看文件

@ -6,3 +6,4 @@ install: |
sudo apt-get install crystal
script:
- crystal build crisp.cr
- crystal spec

+ 0
- 0
spec/.gitkeep 查看文件


+ 15
- 0
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

+ 5
- 0
spec/helper.cr 查看文件

@ -0,0 +1,5 @@
require "spec"
macro require_crisp(module)
require "../../src/crisp/{{module}}"
end

+ 10
- 2
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 kp">self.print(eval_string(line))
rescue e
puts e.message
end

Loading…
取消
儲存