diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-09-22 11:31:45 -0400 |
---|---|---|
committer | Kevin Newton <kddnewton@gmail.com> | 2023-09-27 12:10:23 -0400 |
commit | b18e05b18f5987cd5ce506af380558fd192d2d1c (patch) | |
tree | 291306ebd8204baf9f0ffc5bc8411ec2b6490116 /test/yarp | |
parent | 3cec94624b0a0b308df03f5dba22dd5eb2e4f515 (diff) | |
download | ruby-b18e05b18f5987cd5ce506af380558fd192d2d1c.tar.gz |
[ruby/yarp] Split up compiler versus visitor
https://github.com/ruby/yarp/commit/2e6baa3f19
Diffstat (limited to 'test/yarp')
-rw-r--r-- | test/yarp/compiler_test.rb | 30 | ||||
-rw-r--r-- | test/yarp/desugar_compiler_test.rb (renamed from test/yarp/desugar_visitor_test.rb) | 6 |
2 files changed, 33 insertions, 3 deletions
diff --git a/test/yarp/compiler_test.rb b/test/yarp/compiler_test.rb new file mode 100644 index 0000000000..141e183469 --- /dev/null +++ b/test/yarp/compiler_test.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require_relative "test_helper" + +module YARP + class CompilerTest < TestCase + class SExpressions < YARP::Compiler + def visit_arguments_node(node) + [:arguments, super] + end + + def visit_call_node(node) + [:call, super] + end + + def visit_integer_node(node) + [:integer] + end + + def visit_program_node(node) + [:program, super] + end + end + + def test_compiler + expected = [:program, [[[:call, [[:integer], [:arguments, [[:integer]]]]]]]] + assert_equal expected, YARP.parse("1 + 2").value.accept(SExpressions.new) + end + end +end diff --git a/test/yarp/desugar_visitor_test.rb b/test/yarp/desugar_compiler_test.rb index 3966d7bfcb..8d2b207fed 100644 --- a/test/yarp/desugar_visitor_test.rb +++ b/test/yarp/desugar_compiler_test.rb @@ -3,7 +3,7 @@ require_relative "test_helper" module YARP - class DesugarVisitorTest < TestCase + class DesugarCompilerTest < TestCase def test_and_write assert_desugars("(AndNode (ClassVariableReadNode) (ClassVariableWriteNode (CallNode)))", "@@foo &&= bar") assert_not_desugared("Foo::Bar &&= baz", "Desugaring would execute Foo twice or need temporary variables") @@ -72,7 +72,7 @@ module YARP end def assert_desugars(expected, source) - ast = YARP.parse(source).value.accept(DesugarVisitor.new) + ast = YARP.parse(source).value.accept(DesugarCompiler.new) assert_equal expected, ast_inspect(ast.statements.body.last) ast.accept(EnsureEveryNodeOnceInAST.new) @@ -80,7 +80,7 @@ module YARP def assert_not_desugared(source, reason) ast = YARP.parse(source).value - assert_equal_nodes(ast, ast.accept(DesugarVisitor.new)) + assert_equal_nodes(ast, ast.accept(DesugarCompiler.new)) end end end |