diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-09-11 12:32:25 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-09-11 21:42:03 +0000 |
commit | b7ffa74d583100bb41b43bfdc8d883aea2e1fcad (patch) | |
tree | d06cdfa75b81a48efd3326ee1b8f68222f90c42d /test | |
parent | aa69bd841aa5c35429e0dc08f5955a0dbd9176e5 (diff) |
[ruby/yarp] Introduce MatchLastLineNode and InterpolatedMatchLastLineNode
These are replacements for regular expressions when they are used
alone as the predicate of a conditional. That's because they are
significantly different from a regular expression because they are
not evaluated for truthyness, but instead evaluated as a match
against the last line read by an IO object.
https://github.com/ruby/yarp/commit/0f1c7780e8
Diffstat (limited to 'test')
-rw-r--r-- | test/yarp/location_test.rb | 8 | ||||
-rw-r--r-- | test/yarp/snapshots/unparser/corpus/literal/if.txt | 2 | ||||
-rw-r--r-- | test/yarp/snapshots/whitequark/cond_match_current_line.txt | 4 |
3 files changed, 11 insertions, 3 deletions
diff --git a/test/yarp/location_test.rb b/test/yarp/location_test.rb index 6b219a0b36..46cae55cac 100644 --- a/test/yarp/location_test.rb +++ b/test/yarp/location_test.rb @@ -450,6 +450,10 @@ module YARP assert_location(IntegerNode, "0o1_000") end + def test_InterpolatedMatchLastLineNode + assert_location(InterpolatedMatchLastLineNode, "if /foo \#{bar}/ then end", 3...15, &:predicate) + end + def test_InterpolatedRegularExpressionNode assert_location(InterpolatedRegularExpressionNode, "/\#{foo}/") end @@ -525,6 +529,10 @@ module YARP assert_location(LocalVariableWriteNode, "foo = bar") end + def test_MatchLastLineNode + assert_location(MatchLastLineNode, "if /foo/ then end", 3...8, &:predicate) + end + def test_MatchPredicateNode assert_location(MatchPredicateNode, "foo in bar") end diff --git a/test/yarp/snapshots/unparser/corpus/literal/if.txt b/test/yarp/snapshots/unparser/corpus/literal/if.txt index 88cc011900..4a439644b0 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/if.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/if.txt @@ -6,7 +6,7 @@ ├── @ IfNode (location: (0...18)) │ ├── if_keyword_loc: (0...2) = "if" │ ├── predicate: - │ │ @ RegularExpressionNode (location: (3...8)) + │ │ @ MatchLastLineNode (location: (3...8)) │ │ ├── opening_loc: (3...4) = "/" │ │ ├── content_loc: (4...7) = "foo" │ │ ├── closing_loc: (7...8) = "/" diff --git a/test/yarp/snapshots/whitequark/cond_match_current_line.txt b/test/yarp/snapshots/whitequark/cond_match_current_line.txt index e5902bce8f..88e35d7ca0 100644 --- a/test/yarp/snapshots/whitequark/cond_match_current_line.txt +++ b/test/yarp/snapshots/whitequark/cond_match_current_line.txt @@ -5,7 +5,7 @@ └── body: (length: 2) ├── @ CallNode (location: (0...6)) │ ├── receiver: - │ │ @ RegularExpressionNode (location: (1...6)) + │ │ @ MatchLastLineNode (location: (1...6)) │ │ ├── opening_loc: (1...2) = "/" │ │ ├── content_loc: (2...5) = "wat" │ │ ├── closing_loc: (5...6) = "/" @@ -22,7 +22,7 @@ └── @ IfNode (location: (8...21)) ├── if_keyword_loc: (8...10) = "if" ├── predicate: - │ @ RegularExpressionNode (location: (11...16)) + │ @ MatchLastLineNode (location: (11...16)) │ ├── opening_loc: (11...12) = "/" │ ├── content_loc: (12...15) = "wat" │ ├── closing_loc: (15...16) = "/" |