Sha256: 25b1f9a1f145eb04b554bcdc3003ec7996898915dcee8982b8479dbfdd8b212b
Contents?: true
Size: 1.69 KB
Versions: 2
Compression:
Stored size: 1.69 KB
Contents
require 'helper' require 'parser/ruby18' class TestSourceCommentAssociator < Minitest::Test def associate(code) parser = Parser::Ruby18.new buffer = Parser::Source::Buffer.new('(comments)') buffer.source = code ast, comments = parser.parse_with_comments(buffer) associations = Parser::Source::Comment.associate(ast, comments) [ ast, associations ] end def test_associate ast, associations = associate(<<-END) #!/usr/bin/env ruby # coding: utf-8 # Class comment # another class comment class Foo # attr_accessor comment attr_accessor :foo # method comment def bar # expr comment 1 + # intermediate comment 2 # stray comment end end END klass_node = ast attr_accessor_node = ast.children[2].children[0] method_node = ast.children[2].children[1] expr_node = method_node.children[2] intermediate_node = expr_node.children[2] assert_equal 5, associations.size assert_equal ['# Class comment', '# another class comment'], associations[klass_node].map(&:text) assert_equal ['# attr_accessor comment'], associations[attr_accessor_node].map(&:text) assert_equal ['# method comment'], associations[method_node].map(&:text) assert_equal ['# expr comment'], associations[expr_node].map(&:text) assert_equal ['# intermediate comment'], associations[intermediate_node].map(&:text) end def test_associate_no_body ast, associations = associate(<<-END) # foo class Foo end END assert_equal 1, associations.size assert_equal ['# foo'], associations[ast].map(&:text) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
parser-2.0.0.pre5 | test/test_source_comment_associator.rb |
parser-2.0.0.pre4 | test/test_source_comment_associator.rb |