Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 13f193a749
Fetching contributors…

Cannot retrieve contributors at this time

113 lines (102 sloc) 3.473 kb
require 'spec_helper'
module Schemer
describe Parser do
subject { Parser.new }
let(:lexer) { Lexer.new }
describe "Strings" do
it "suffer no change" do
text = "(proc \"my string\")"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should eq("my string")
end
end
describe "Integers" do
it "are typecasted from string" do
text = "(proc 29)"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should eq(29)
end
end
describe "Floats" do
it "are typecasted from string" do
text = "(proc 29.42)"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should eq(29.42)
end
end
describe "Chars" do
it "are transformed into CharacterLiterals" do
text = "(proc #\\z)"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should be_an(AST::CharacterLiteral)
end
end
describe "Booleans" do
it "are directly evaluated" do
text = "(proc #f #t)"
parsed = subject.apply(lexer.parse text).first.elements
parsed[1].should be_false
parsed[2].should be_true
end
end
describe "Identifiers" do
describe "Regular identifiers" do
it "are transformed into Identifiers" do
text = "(proc my_identifier)"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should be_an(AST::Identifier)
end
end
describe "Quoted identifiers" do
it "are transformed into QuotedIdentifiers" do
text = "(proc 'quoted_identifier)"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should be_an(AST::QuotedIdentifier)
end
end
end
describe "Lists" do
describe "Regular lists" do
it 'are transformed into Lists' do
text = "(lambda (1 2 3))"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should be_an(AST::List)
parsed.elements[0].should eq(1)
parsed.elements[1].should eq(2)
parsed.elements[2].should eq(3)
end
end
describe "Quoted lists" do
it 'are transformed into QuotedLists' do
text = "(lambda '(1 2 3))"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should be_an(AST::QuotedList)
parsed.elements[0].should eq(1)
parsed.elements[1].should eq(2)
parsed.elements[2].should eq(3)
end
end
describe "Vectors" do
it 'are transformed into Vectors' do
text = "(lambda #(1 2 3))"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should be_an(AST::Vector)
parsed.elements[0].should eq(1)
parsed.elements[1].should eq(2)
parsed.elements[2].should eq(3)
end
end
describe "Pairs" do
it 'are combined into Lists' do
text = "(lambda (1 . (2 3)))"
parsed = subject.apply(lexer.parse text).first.elements.last
parsed.should be_an(AST::List)
parsed.elements.first.should == 1
parsed.elements.last.should be_an(AST::List)
parsed.elements.last.elements[0].should eq(2)
parsed.elements.last.elements[1].should eq(3)
end
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.