diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-09-11 15:26:42 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-09-14 19:16:39 +0000 |
commit | 0d33bc0cde5b9eca805cec1133e2c48ebdea5c84 (patch) | |
tree | 2b4cd73aa78868fdbc5f1137d68a7c1a2e2dcc7b /test | |
parent | 0a8f3670d1c1aa4ec58a08642cccf5ee5dbf95ae (diff) | |
download | ruby-0d33bc0cde5b9eca805cec1133e2c48ebdea5c84.tar.gz |
[ruby/yarp] Simplify multi-target parsing
This simplifies how we handle multi-targets, and also fixes a bug we
had where for loops were always getting multi-targets, even when there
was only a single target.
https://github.com/ruby/yarp/commit/31eb8b7ad5
Diffstat (limited to 'test')
-rw-r--r-- | test/yarp/errors_test.rb | 4 | ||||
-rw-r--r-- | test/yarp/snapshots/for.txt | 40 | ||||
-rw-r--r-- | test/yarp/snapshots/unparser/corpus/literal/for.txt | 20 | ||||
-rw-r--r-- | test/yarp/snapshots/whitequark/for.txt | 20 |
4 files changed, 26 insertions, 58 deletions
diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 4a269d79ec..feecad7c3f 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -42,7 +42,7 @@ module YARP ) assert_errors expected, "for in 1..10\ni\nend", [ - ["Expected an index after `for`", 0..0] + ["Expected an index after `for`", 0..3] ] end @@ -58,7 +58,7 @@ module YARP ) assert_errors expected, "for end", [ - ["Expected an index after `for`", 0..0], + ["Expected an index after `for`", 0..3], ["Expected an `in` after the index in a `for` statement", 3..3], ["Expected a collection after the `in` in a `for` statement", 3..3] ] diff --git a/test/yarp/snapshots/for.txt b/test/yarp/snapshots/for.txt index 3475d585e2..e8b3868b7b 100644 --- a/test/yarp/snapshots/for.txt +++ b/test/yarp/snapshots/for.txt @@ -5,13 +5,9 @@ └── body: (length: 6) ├── @ ForNode (location: (0...20)) │ ├── index: - │ │ @ MultiTargetNode (location: (4...5)) - │ │ ├── targets: (length: 1) - │ │ │ └── @ LocalVariableTargetNode (location: (4...5)) - │ │ │ ├── name: :i - │ │ │ └── depth: 0 - │ │ ├── lparen_loc: ∅ - │ │ └── rparen_loc: ∅ + │ │ @ LocalVariableTargetNode (location: (4...5)) + │ │ ├── name: :i + │ │ └── depth: 0 │ ├── collection: │ │ @ RangeNode (location: (9...14)) │ │ ├── left: @@ -34,13 +30,9 @@ │ └── end_keyword_loc: (17...20) = "end" ├── @ ForNode (location: (22...44)) │ ├── index: - │ │ @ MultiTargetNode (location: (26...27)) - │ │ ├── targets: (length: 1) - │ │ │ └── @ LocalVariableTargetNode (location: (26...27)) - │ │ │ ├── name: :i - │ │ │ └── depth: 0 - │ │ ├── lparen_loc: ∅ - │ │ └── rparen_loc: ∅ + │ │ @ LocalVariableTargetNode (location: (26...27)) + │ │ ├── name: :i + │ │ └── depth: 0 │ ├── collection: │ │ @ RangeNode (location: (31...36)) │ │ ├── left: @@ -130,13 +122,9 @@ │ └── end_keyword_loc: (91...94) = "end" ├── @ ForNode (location: (96...119)) │ ├── index: - │ │ @ MultiTargetNode (location: (100...101)) - │ │ ├── targets: (length: 1) - │ │ │ └── @ LocalVariableTargetNode (location: (100...101)) - │ │ │ ├── name: :i - │ │ │ └── depth: 0 - │ │ ├── lparen_loc: ∅ - │ │ └── rparen_loc: ∅ + │ │ @ LocalVariableTargetNode (location: (100...101)) + │ │ ├── name: :i + │ │ └── depth: 0 │ ├── collection: │ │ @ RangeNode (location: (105...110)) │ │ ├── left: @@ -159,13 +147,9 @@ │ └── end_keyword_loc: (116...119) = "end" └── @ ForNode (location: (121...143)) ├── index: - │ @ MultiTargetNode (location: (125...126)) - │ ├── targets: (length: 1) - │ │ └── @ LocalVariableTargetNode (location: (125...126)) - │ │ ├── name: :i - │ │ └── depth: 0 - │ ├── lparen_loc: ∅ - │ └── rparen_loc: ∅ + │ @ LocalVariableTargetNode (location: (125...126)) + │ ├── name: :i + │ └── depth: 0 ├── collection: │ @ RangeNode (location: (130...135)) │ ├── left: diff --git a/test/yarp/snapshots/unparser/corpus/literal/for.txt b/test/yarp/snapshots/unparser/corpus/literal/for.txt index 682c2bcb14..62fde3418d 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/for.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/for.txt @@ -13,13 +13,9 @@ │ │ └── arguments: (length: 1) │ │ └── @ ForNode (location: (4...29)) │ │ ├── index: - │ │ │ @ MultiTargetNode (location: (8...9)) - │ │ │ ├── targets: (length: 1) - │ │ │ │ └── @ LocalVariableTargetNode (location: (8...9)) - │ │ │ │ ├── name: :a - │ │ │ │ └── depth: 0 - │ │ │ ├── lparen_loc: ∅ - │ │ │ └── rparen_loc: ∅ + │ │ │ @ LocalVariableTargetNode (location: (8...9)) + │ │ │ ├── name: :a + │ │ │ └── depth: 0 │ │ ├── collection: │ │ │ @ CallNode (location: (13...16)) │ │ │ ├── receiver: ∅ @@ -54,13 +50,9 @@ │ └── name: "bar" ├── @ ForNode (location: (31...56)) │ ├── index: - │ │ @ MultiTargetNode (location: (35...36)) - │ │ ├── targets: (length: 1) - │ │ │ └── @ LocalVariableTargetNode (location: (35...36)) - │ │ │ ├── name: :a - │ │ │ └── depth: 0 - │ │ ├── lparen_loc: ∅ - │ │ └── rparen_loc: ∅ + │ │ @ LocalVariableTargetNode (location: (35...36)) + │ │ ├── name: :a + │ │ └── depth: 0 │ ├── collection: │ │ @ CallNode (location: (40...43)) │ │ ├── receiver: ∅ diff --git a/test/yarp/snapshots/whitequark/for.txt b/test/yarp/snapshots/whitequark/for.txt index daf73081e6..285dadd26d 100644 --- a/test/yarp/snapshots/whitequark/for.txt +++ b/test/yarp/snapshots/whitequark/for.txt @@ -5,13 +5,9 @@ └── body: (length: 2) ├── @ ForNode (location: (0...24)) │ ├── index: - │ │ @ MultiTargetNode (location: (4...5)) - │ │ ├── targets: (length: 1) - │ │ │ └── @ LocalVariableTargetNode (location: (4...5)) - │ │ │ ├── name: :a - │ │ │ └── depth: 0 - │ │ ├── lparen_loc: ∅ - │ │ └── rparen_loc: ∅ + │ │ @ LocalVariableTargetNode (location: (4...5)) + │ │ ├── name: :a + │ │ └── depth: 0 │ ├── collection: │ │ @ CallNode (location: (9...12)) │ │ ├── receiver: ∅ @@ -47,13 +43,9 @@ │ └── end_keyword_loc: (21...24) = "end" └── @ ForNode (location: (26...48)) ├── index: - │ @ MultiTargetNode (location: (30...31)) - │ ├── targets: (length: 1) - │ │ └── @ LocalVariableTargetNode (location: (30...31)) - │ │ ├── name: :a - │ │ └── depth: 0 - │ ├── lparen_loc: ∅ - │ └── rparen_loc: ∅ + │ @ LocalVariableTargetNode (location: (30...31)) + │ ├── name: :a + │ └── depth: 0 ├── collection: │ @ CallNode (location: (35...38)) │ ├── receiver: ∅ |