Sha256: 6507cc75bb40d5b0dad15d7460c1200a4e3e1de7bcb98e3efc1911432dcf8d56

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
require 'ruby_parser'

describe 'Using RipperRubyParser and RubyParser' do
  def to_line_numbers(exp)
    exp.map! do |sub_exp|
      if sub_exp.is_a? Sexp
        to_line_numbers sub_exp
      else
        sub_exp
      end
    end

    if exp.sexp_type == :scope
      exp
    else
      s(:line_number, exp.line, exp)
    end
  end

  let :newparser do
    RipperRubyParser::Parser.new
  end

  let :oldparser do
    RubyParser.new
  end

  describe 'for a multi-line program' do
    let :program do
      <<-END
      class Foo
        def foo()
          bar()
          baz(qux)
        end
      end

      module Bar
        @@baz = {}
      end
      END
    end

    let :original do
      oldparser.parse program
    end

    let :imitation do
      newparser.parse program
    end

    it 'gives the same result' do
      imitation.must_equal original
    end

    it 'gives the same result with line numbers' do
      formatted(to_line_numbers(imitation)).
        must_equal formatted(to_line_numbers(original))
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ripper_ruby_parser-1.4.2 test/end_to_end/line_numbering_test.rb
ripper_ruby_parser-1.4.1 test/end_to_end/line_numbering_test.rb
ripper_ruby_parser-1.4.0 test/end_to_end/line_numbering_test.rb
ripper_ruby_parser-1.3.0 test/end_to_end/line_numbering_test.rb
ripper_ruby_parser-1.2.0 test/end_to_end/line_numbering_test.rb