summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorydah <t.yudai92@gmail.com>2024-11-06 12:14:01 +0900
committerYudai Takada <t.yudai92@gmail.com>2025-01-04 07:34:49 +0900
commit607b1b3d7628b1f94f086ce1dfe67789179cf906 (patch)
tree5929a66656adf7d2064cd1423e4e95ed08ee6fe4 /test/ruby
parent4c192011422dc04902ddf930ff22be223325a35d (diff)
Implement YIELD NODE locations
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e 'def foo; yield end' @ ProgramNode (location: (1,0)-(1,18)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,18)) +-- body: (length: 1) +-- @ DefNode (location: (1,0)-(1,18)) +-- name: :foo +-- name_loc: (1,4)-(1,7) = "foo" +-- receiver: nil +-- parameters: nil +-- body: | @ StatementsNode (location: (1,9)-(1,14)) | +-- body: (length: 1) | +-- @ YieldNode (location: (1,9)-(1,14)) | +-- keyword_loc: (1,9)-(1,14) = "yield" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +-- lparen_loc: nil ^^^^^^^^^^^^^^^^^^^ | +-- arguments: nil | +-- rparen_loc: nil ^^^^^^^^^^^^^^^^^^^ +-- locals: [] +-- def_keyword_loc: (1,0)-(1,3) = "def" +-- operator_loc: nil +-- lparen_loc: nil +-- rparen_loc: nil +-- equal_loc: nil +-- end_keyword_loc: (1,15)-(1,18) = "end" ```
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_ast.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index 4e449410f1..e456f5b7b5 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -1517,6 +1517,20 @@ dummy
assert_locations(node.children[-1].locations, [[1, 0, 1, 9], [1, 2, 1, 7], nil])
end
+ def test_yield_locations
+ node = ast_parse("def foo; yield end")
+ assert_locations(node.children[-1].children[-1].children[-1].locations, [[1, 9, 1, 14], [1, 9, 1, 14], nil, nil])
+
+ node = ast_parse("def foo; yield() end")
+ assert_locations(node.children[-1].children[-1].children[-1].locations, [[1, 9, 1, 16], [1, 9, 1, 14], [1, 14, 1, 15], [1, 15, 1, 16]])
+
+ node = ast_parse("def foo; yield 1, 2 end")
+ assert_locations(node.children[-1].children[-1].children[-1].locations, [[1, 9, 1, 19], [1, 9, 1, 14], nil, nil])
+
+ node = ast_parse("def foo; yield(1, 2) end")
+ assert_locations(node.children[-1].children[-1].children[-1].locations, [[1, 9, 1, 20], [1, 9, 1, 14], [1, 14, 1, 15], [1, 19, 1, 20]])
+ end
+
private
def ast_parse(src, **options)
begin