Sha256: 5acf6b9c19c1e70434997aa7fd37bb4faef9cc3435a48f34f2c07df16835734e

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'
require 'parser/current'

describe Unparser::Comments, '#take_before' do

  let(:ast)      { ast_and_comments[0] }
  let(:comments) { ast_and_comments[1] }
  let(:object)   { described_class.new(comments) }

  context 'usual case' do

    let(:ast_and_comments) do
      Parser::CurrentRuby.parse_with_comments(<<-RUBY)
        def hi # EOL 1
          # comment
        end # EOL 2
      RUBY
    end

    it 'should return no comments none are before the node' do
      expect(object.take_before(ast, :expression)).to eql([])
    end

    it 'should only the comments that are before the specified part of the node' do
      expect(object.take_before(ast, :end)).to eql(comments.first(2))
      expect(object.take_all).to eql([comments[2]])
    end
  end

  context 'when node does not respond to source part' do

    let(:ast_and_comments) do
      Parser::CurrentRuby.parse_with_comments(<<-RUBY)
        expression ? :foo : :bar # EOL 1
        # EOL 2
      RUBY
    end

    it 'should return no comments none are before the node' do
      expect(object.take_before(ast, :expression)).to eql([])
    end

    it 'should only the comments that are before the specified part of the node' do
      expect(object.take_before(ast, :end)).to eql([])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unparser-0.1.5 spec/unit/unparser/comments/take_before_spec.rb