diff options
| author | Benoit Daloze <eregontp@gmail.com> | 2024-02-17 12:02:18 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-02-17 15:35:51 +0000 |
| commit | 13d2a3a88fe88fd3fbc01bcd981c68732ff9404e (patch) | |
| tree | ed03cf29b71bb45c9342e32765d7c7b7a4bee7d0 /test | |
| parent | 3dccb716daaee74d2ae00a5766fe1779fe220a81 (diff) | |
[ruby/prism] Fix visitor in desugar test
* The #visit method is no longer called for every node since 2e6baa3.
* As a consequence EnsureEveryNodeOnceInAST was only visiting ProgramNode
for `visitor.visit(ast)` and no nodes at all for `ast.accept(visitor)`.
https://github.com/ruby/prism/commit/683513620a
Diffstat (limited to 'test')
| -rw-r--r-- | test/prism/desugar_compiler_test.rb | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/test/prism/desugar_compiler_test.rb b/test/prism/desugar_compiler_test.rb index c72e141c6b..1a1d580d2d 100644 --- a/test/prism/desugar_compiler_test.rb +++ b/test/prism/desugar_compiler_test.rb @@ -54,20 +54,14 @@ module Prism # Ensure every node is only present once in the AST. # If the same node is present twice it would most likely indicate it is executed twice, which is invalid semantically. # This also acts as a sanity check that Node#child_nodes returns only nodes or nil (which caught a couple bugs). - class EnsureEveryNodeOnceInAST < Visitor - def initialize - @all_nodes = {}.compare_by_identity + def ensure_every_node_once_in_ast(node, all_nodes = {}.compare_by_identity) + if all_nodes.include?(node) + raise "#{node.inspect} is present multiple times in the desugared AST and likely executed multiple times" + else + all_nodes[node] = true end - - def visit(node) - if node - if @all_nodes.include?(node) - raise "#{node.inspect} is present multiple times in the desugared AST and likely executed multiple times" - else - @all_nodes[node] = true - end - end - super(node) + node.child_nodes.each do |child| + ensure_every_node_once_in_ast(child, all_nodes) unless child.nil? end end @@ -75,7 +69,7 @@ module Prism ast = Prism.parse(source).value.accept(DesugarCompiler.new) assert_equal expected, ast_inspect(ast.statements.body.last) - ast.accept(EnsureEveryNodeOnceInAST.new) + ensure_every_node_once_in_ast(ast) end def assert_not_desugared(source, reason) |
