Bläddra i källkod

add first spec

master
rhysd 9 år sedan
förälder
incheckning
dab227b4da
5 ändrade filer med 31 tillägg och 2 borttagningar
  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 Visa fil

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

+ 0
- 0
spec/.gitkeep Visa fil


+ 15
- 0
spec/crisp/interpreter_spec.cr Visa fil

@ -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 Visa fil

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

+ 10
- 2
src/crisp/interpreter.cr Visa fil

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

Laddar…
Avbryt
Spara