diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-09-26 13:57:20 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-09-26 18:07:55 +0000 |
commit | a436805d3b3b82b34bc60c07763b31da2aba95b9 (patch) | |
tree | b91366e49d4a3c490d4af7fec61162737e499442 /test/yarp | |
parent | 154bd04ee228ee3bee173a479d397074268cd4d6 (diff) | |
download | ruby-a436805d3b3b82b34bc60c07763b31da2aba95b9.tar.gz |
[ruby/yarp] Remove visitor usage to not rely on overriding visit
https://github.com/ruby/yarp/commit/6903860981
Diffstat (limited to 'test/yarp')
-rw-r--r-- | test/yarp/newline_test.rb | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/test/yarp/newline_test.rb b/test/yarp/newline_test.rb index ba82b5ef45..7fb6d173bb 100644 --- a/test/yarp/newline_test.rb +++ b/test/yarp/newline_test.rb @@ -36,12 +36,7 @@ module YARP result = YARP.parse_file(filepath) assert_empty result.errors - - result.mark_newlines! - visitor = NewlineVisitor.new(result.source) - - result.value.accept(visitor) - actual = visitor.newlines + actual = yarp_lines(result) source.each_line.with_index(1) do |line, line_number| # Lines like `while (foo = bar)` result in two line flags in the @@ -92,5 +87,19 @@ module YARP lines.sort end + + def yarp_lines(result) + result.mark_newlines! + + queue = [result.value] + newlines = [] + + while node = queue.shift + queue.concat(node.compact_child_nodes) + newlines << result.source.line(node.location.start_offset) if node&.newline? + end + + newlines + end end end |