diff options
author | Vinicius Stock <vinicius.stock@shopify.com> | 2023-09-07 13:44:35 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-09-08 18:10:26 +0000 |
commit | 6050b5a4e860b05f6b5e553d5883330a908079f9 (patch) | |
tree | 8082354fbd8ef7ffbffde11e661692c4b7704283 /test | |
parent | 7f53da94fb23687ef3bea0507199196a00ca26f8 (diff) |
[ruby/yarp] Add ParseResult#attach_comments! to tie comments to their locations
https://github.com/ruby/yarp/commit/ddc699156f
Co-authored-by: Kevin Newton <kddnewton@users.noreply.github.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/yarp/comments_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/yarp/comments_test.rb b/test/yarp/comments_test.rb index ac91eab4ac..ec419a9fff 100644 --- a/test/yarp/comments_test.rb +++ b/test/yarp/comments_test.rb @@ -55,6 +55,30 @@ module YARP assert_comment source, :embdoc, 0..24 end + def test_attaching_comments + source = <<~RUBY + # Foo class + class Foo + # bar method + def bar + # baz invocation + baz + end # bar end + end # Foo end + RUBY + + result = YARP.parse(source) + result.attach_comments! + tree = result.value + class_node = tree.statements.body.first + method_node = class_node.body.body.first + call_node = method_node.body.body.first + + assert_equal("# Foo class\n# Foo end\n", class_node.location.comments.map { |c| c.location.slice }.join) + assert_equal("# bar method\n# bar end\n", method_node.location.comments.map { |c| c.location.slice }.join) + assert_equal("# baz invocation\n", call_node.location.comments.map { |c| c.location.slice }.join) + end + private def assert_comment(source, type, location) |