You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crafting-interpreters/ruby/test/lox/test_ast_printer.rb

23 lines
524 B

require_relative "../test_helper"
require "lox/ast_printer"
require "lox/expr"
require "lox/token"
class TestAstPrinter < Lox::Test
def test_ast_printer
expr = Lox::Expr::Binary.new(
Lox::Expr::Unary.new(
Lox::Token.new(:MINUS, ?-, nil, 1),
Lox::Expr::Literal.new(123),
),
Lox::Token.new(:STAR, ?*, nil, 1),
Lox::Expr::Grouping.new(
Lox::Expr::Literal.new(45.67),
),
)
assert_equal "(* (- 123) (group 45.67))", Lox::AstPrinter.new.print(expr)
end
end