Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Parser test with minitest

  • Loading branch information...
commit ca591357ed8e86ba05a6ed95c2fdd731e8195184 1 parent 655d223
@txus authored
Showing with 95 additions and 0 deletions.
  1. +95 −0 test/schemer/parser_test.rb
View
95 test/schemer/parser_test.rb
@@ -0,0 +1,95 @@
+require 'test_helper'
+
+module Schemer
+ class ParserTest < MiniTest::Unit::TestCase
+ def setup
+ @lexer = Lexer.new
+ @parser = Parser.new
+ end
+
+ def test_strings_suffer_no_change
+ text = "(proc \"my string\")"
+ parsed = parse(text).first.elements.last
+ assert_equal "my string", parsed
+ end
+
+ def test_integers_are_typecasted
+ text = "(proc 29)"
+ parsed = parse(text).first.elements.last
+ assert_equal 29, parsed
+ end
+
+ def test_floats_are_typecasted
+ text = "(proc 29.42)"
+ parsed = parse(text).first.elements.last
+ assert_equal 29.42, parsed
+ end
+
+ def test_chars_are_transformed_into_character_literals
+ text = "(proc #\\z)"
+ parsed = parse(text).first.elements.last
+ assert_instance_of AST::CharacterLiteral, parsed
+ end
+
+ def test_booleans_are_directly_evaluated
+ text = "(proc #f #t)"
+ parsed = parse(text).first.elements
+ assert_equal false, parsed[1]
+ assert_equal true, parsed[2]
+ end
+
+ def test_identifiers
+ text = "(proc my_identifier)"
+ parsed = parse(text).first.elements.last
+ assert_instance_of AST::Identifier, parsed
+ end
+
+ def test_quoted_identifiers
+ text = "(proc 'quoted_identifier)"
+ parsed = parse(text).first.elements.last
+ assert_instance_of AST::QuotedIdentifier, parsed
+ end
+
+ def test_lists
+ text = "(lambda (1 2 3))"
+ parsed = parse(text).first.elements.last
+ assert_instance_of AST::List, parsed
+ assert_equal 1, parsed.elements[0]
+ assert_equal 2, parsed.elements[1]
+ assert_equal 3, parsed.elements[2]
+ end
+
+ def test_quoted_lists
+ text = "(lambda '(1 2 3))"
+ parsed = parse(text).first.elements.last
+ assert_instance_of AST::QuotedList, parsed
+ assert_equal 1, parsed.elements[0]
+ assert_equal 2, parsed.elements[1]
+ assert_equal 3, parsed.elements[2]
+ end
+
+ def test_vector
+ text = "(lambda #(1 2 3))"
+ parsed = parse(text).first.elements.last
+ assert_instance_of AST::Vector, parsed
+ assert_equal 1, parsed.elements[0]
+ assert_equal 2, parsed.elements[1]
+ assert_equal 3, parsed.elements[2]
+ end
+
+ def test_pairs_are_combined_into_lists
+ text = "(lambda (1 . (2 3)))"
+ parsed = parse(text).first.elements.last
+ assert_equal 1, parsed.elements.first
+ assert_instance_of AST::List, parsed.elements.last
+ assert_equal 2, parsed.elements.last.elements[0]
+ assert_equal 3, parsed.elements.last.elements[1]
+ end
+
+ private
+
+ def parse(input)
+ @parser.apply(@lexer.parse input)
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.