Sha256: 16e454951083defe19f239c219fe9ffd0a0cde0961295efad9eba8f6e06d7df6

Contents?: true

Size: 901 Bytes

Versions: 3

Compression:

Stored size: 901 Bytes

Contents

require 'spec_helper'
require 'parser/current'

describe Unparser::Comments, '#take_eol_comments' do

  let(:ast_and_comments) do
    Parser::CurrentRuby.parse_with_comments(<<-RUBY)
def hi # EOL 1
=begin
doc comment
=end
end # EOL 2
    RUBY
  end
  let(:ast)              { ast_and_comments[0] }
  let(:comments)         { ast_and_comments[1] }
  let(:object)           { described_class.new(comments) }

  it 'should return no comments if nothing has been consumed' do
    expect(object.take_eol_comments).to eql([])
  end

  it 'should return comments once their line has been consumed' do
    object.consume(ast, :name)
    expect(object.take_eol_comments).to eql([comments[0]])
  end

  it 'should leave doc comments to be taken later' do
    object.consume(ast)
    expect(object.take_eol_comments).to eql([comments[0], comments[2]])
    expect(object.take_all).to eql([comments[1]])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unparser-0.1.5 spec/unit/unparser/comments/take_eol_comments_spec.rb
unparser-0.1.4 spec/unit/unparser/comments/take_eol_comments_spec.rb
unparser-0.1.3 spec/unit/unparser/comments/take_eol_comments_spec.rb