Created
July 31, 2020 06:05
-
-
Save benphelps/5698b03896ef677226c51d527af0b048 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./spec_helper" | |
def test_statement(statement : AST::LetStatement, name : String) | |
it "expectes token_literal to be let" do | |
statement.token_literal.should eq("let") | |
end | |
it "should be an AST::LetStatement" do | |
statement.should be_a(AST::LetStatement) | |
end | |
if statement.is_a?(AST::LetStatement) | |
it "should have the correct name" do | |
statement.name.value.should eq(name) | |
end | |
it "should have the correct token_literal" do | |
statement.name.token_literal.should eq(name) | |
end | |
end | |
end | |
describe Parser::Parser do | |
describe "LetStatement" do | |
input = "let not = 5;let focused = 10;let test = 838383;" | |
lexer = Lexer::Lexer.new(input) | |
parser = Parser::Parser.new(lexer) | |
program = parser.parse_program | |
check_parser_errors(parser) | |
it "should not be nil" do | |
program.should_not be_nil | |
end | |
it "should contain 3 statements" do | |
program.statements.size.should eq(3) | |
end | |
tests = [ | |
"x", | |
"y", | |
"foobar", | |
] | |
tests.each_with_index do |expected_identifier, i| | |
test_statement(program.statements[i], expected_identifier) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment