Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Further tests

  • Loading branch information...
commit 13f193a74929aa4cc108948f3245253ef0660696 1 parent f13eb4d
@txus authored
View
2  Gemfile.lock
@@ -21,6 +21,7 @@ GEM
configuration (>= 0.0.5)
rake (>= 0.8.1)
minitest (2.0.2)
+ mocha (0.9.12)
open_gem (1.4.2)
launchy (~> 0.3.5)
parslet (1.2.0)
@@ -45,6 +46,7 @@ DEPENDENCIES
guard-minitest
guard-rspec
minitest
+ mocha
rb-fsevent
rspec (~> 2.5.0)
schemer!
View
1  schemer.gemspec
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec', '~> 2.5.0'
s.add_development_dependency 'minitest'
+ s.add_development_dependency 'mocha'
s.add_development_dependency 'guard'
s.add_development_dependency 'guard-rspec'
s.add_development_dependency 'guard-minitest'
View
3  test/schemer/interpreter_test.rb → test/schemer/interpreter/interpreter_test.rb
@@ -20,12 +20,11 @@ def test_walks_the_ast_visiting_every_node
interpreter = Interpreter.new(ast)
ast.each do |node|
- node.should_receive(:eval).with(kind_of(Environment))
+ node.expects(:eval).with(kind_of(Environment))
end
interpreter.walk
end
-
end
end
View
50 test/schemer/interpreter/stdlib_test.rb
@@ -0,0 +1,50 @@
+require 'test_helper'
+
+module Schemer
+ class StandardLibraryTest < MiniTest::Unit::TestCase
+
+ def setup
+ @lexer = Lexer.new
+ @parser = Parser.new
+ end
+
+ def test_add
+ assert_evaluates 7, "(+ 3 4)"
+ end
+
+ def test_subtracts
+ assert_evaluates -1, "(- 3 4)"
+ end
+
+ def test_multiplies
+ assert_evaluates 12, "(* 3 4)"
+ end
+
+ def test_divides
+ assert_evaluates 2, "(/ 4 2)"
+ end
+
+ def test_write_prints_to_stdout
+ $stdout.expects(:print).with(4)
+
+ ast = @parser.apply(@lexer.parse "(write 4)")
+ evaluated = Schemer::Interpreter.new(ast).walk
+
+ assert_equal nil, evaluated
+ end
+
+ def test_inspect_returns_the_object_as_string
+ assert_evaluates "#<List [1, 3]>", "(inspect (1 3))"
+ end
+
+ private
+
+ def assert_evaluates(expected, expression)
+ ast = @parser.apply(@lexer.parse expression)
+ evaluated = Schemer::Interpreter.new(ast).walk
+
+ assert_equal expected, evaluated
+ end
+
+ end
+end
View
2  test/test_helper.rb
@@ -2,4 +2,6 @@
require 'minitest/unit'
require 'minitest/autorun'
require 'minitest/pride'
+require 'mocha'
+
require 'schemer'
Please sign in to comment.
Something went wrong with that request. Please try again.