diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2023-08-18 11:54:45 -0400 |
|---|---|---|
| committer | Jemma Issroff <jemmaissroff@gmail.com> | 2023-08-21 10:43:13 -0700 |
| commit | 4fb2b3b6bf434a8dc027ca3a0cc3161e99eee26c (patch) | |
| tree | 85022c322eaedc289e390aa3c39f751f0f3bfe8b /test | |
| parent | 0fd57ee01d60f75f653e72f0b8647748bd422b5d (diff) | |
[ruby/yarp] Ensure correct location with if/elsif, allow FOCUS env var, fix newlines on __END__
https://github.com/ruby/yarp/commit/9da0bc4452
Diffstat (limited to 'test')
| -rw-r--r-- | test/yarp/parse_test.rb | 13 | ||||
| -rw-r--r-- | test/yarp/snapshots/if.txt | 4 | ||||
| -rw-r--r-- | test/yarp/snapshots/seattlerb/if_elsif.txt | 2 |
3 files changed, 15 insertions, 4 deletions
diff --git a/test/yarp/parse_test.rb b/test/yarp/parse_test.rb index 33eb1475f5..c0f3ecf551 100644 --- a/test/yarp/parse_test.rb +++ b/test/yarp/parse_test.rb @@ -34,8 +34,12 @@ class ParseTest < Test::Unit::TestCase # running on Ruby 3.2+. check_ripper = RUBY_VERSION >= "3.2.0" + # The FOCUS environment variable allows you to specify one particular fixture + # to test, instead of all of them. base = File.join(__dir__, "fixtures") - Dir["**/*.txt", base: base].each do |relative| + relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base] + + relatives.each do |relative| # These fail on TruffleRuby due to a difference in Symbol#inspect: :测试 vs :"测试" next if RUBY_ENGINE == "truffleruby" and %w[seattlerb/bug202.txt seattlerb/magic_encoding_comment.txt].include?(relative) @@ -91,6 +95,13 @@ class ParseTest < Test::Unit::TestCase # Next, assert that the newlines are in the expected places. expected_newlines = [0] source.b.scan("\n") { expected_newlines << $~.offset(0)[0] + 1 } + + # If there's a __END__, then we should trip out those newlines because we + # don't actually scan them during parsing (because we don't need to). + if found = result.comments.find { |comment| comment.type == :__END__ } + expected_newlines = expected_newlines[...found.location.start_line] + end + assert_equal expected_newlines, YARP.const_get(:Debug).newlines(source) # This file has changed behavior in Ripper in Ruby 3.3, so we skip it if diff --git a/test/yarp/snapshots/if.txt b/test/yarp/snapshots/if.txt index c12691abfe..d151d6b547 100644 --- a/test/yarp/snapshots/if.txt +++ b/test/yarp/snapshots/if.txt @@ -203,7 +203,7 @@ ProgramNode(0...382)( (269...271) ), nil, - IfNode(274...289)( + IfNode(274...293)( (274...279), MatchPredicateNode(280...289)( CallNode(280...284)( @@ -222,7 +222,7 @@ ProgramNode(0...382)( ), nil, nil, - nil + (290...293) ), (290...293) ), diff --git a/test/yarp/snapshots/seattlerb/if_elsif.txt b/test/yarp/snapshots/seattlerb/if_elsif.txt index 6f1edfb62e..51c89a9a32 100644 --- a/test/yarp/snapshots/seattlerb/if_elsif.txt +++ b/test/yarp/snapshots/seattlerb/if_elsif.txt @@ -5,7 +5,7 @@ ProgramNode(0...18)( (0...2), IntegerNode(3...4)(), nil, - IfNode(6...13)((6...11), IntegerNode(12...13)(), nil, nil, nil), + IfNode(6...18)((6...11), IntegerNode(12...13)(), nil, nil, (15...18)), (15...18) )] ) |
