File: take_eol_comments_spec.rb

package info (click to toggle)
ruby-unparser 0.6.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 936 kB
  • sloc: ruby: 7,691; sh: 6; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'spec_helper'

describe Unparser::Comments, '#take_eol_comments' do

  let(:ast_and_comments) do
    Unparser.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