Browse Source

add first spec

master
rhysd 9 years ago
parent
commit
dab227b4da
5 changed files with 31 additions and 2 deletions
  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 View File

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

+ 0
- 0
spec/.gitkeep View File


+ 15
- 0
spec/crisp/interpreter_spec.cr View File

@ -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 View File

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

+ 10
- 2
src/crisp/interpreter.cr View File

@ -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…
Cancel
Save