Skip to content

Instantly share code, notes, and snippets.

@benphelps
Created July 31, 2020 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benphelps/5698b03896ef677226c51d527af0b048 to your computer and use it in GitHub Desktop.
Save benphelps/5698b03896ef677226c51d527af0b048 to your computer and use it in GitHub Desktop.
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