Sha256: b91292698bb4e9e16fdc2cba75e020d77340f941725cd529f29e9718851b934a

Contents?: true

Size: 1.14 KB

Versions: 14

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'
require 'opal-source-maps'

describe Opal::SourceMap do
  before do
    pathname = 'foo.rb'
    compiler = Opal::Compiler.new("def foo\n123\nend", :file => pathname)
    @source  = compiler.compile
    @map     = Opal::SourceMap.new(compiler.fragments, pathname)
  end

  def js_line_for(code)
    index = @source.split("\n").index {|line| line.include?(code)}
    # 1 based line numbers
    index + 1
  end

  def parsed_map
    SourceMap::Map.from_json(@map.as_json.to_json)
  end

  def mappings
    mappings = []
    # mappings is not exposed on the ext library
    parsed_map.each do |mapping|
      mappings << mapping
    end
    mappings
  end

  it 'does not blow while generating the map' do
    lambda { @map.as_json }.should_not raise_error
  end

  it 'parses the map without error' do
    parsed_map.should_not be_nil
  end

  it 'identifies line numbers' do
    match = mappings.find {|map| map.original.line == 2 }
    # as of Opal 0.10
    match.generated.line.should == js_line_for('return 123')
  end

  it 'uses method names' do
    match = mappings.find {|map| map.original.line == 2 }
    match.name.should == 'foo'
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
opal-0.10.6 spec/opal/core/source_map_spec.rb
opal-0.10.6.beta spec/opal/core/source_map_spec.rb
opal-0.10.5 spec/opal/core/source_map_spec.rb
opal-0.10.4 spec/opal/core/source_map_spec.rb
opal-0.11.0.rc1 spec/opal/core/source_map_spec.rb
opal-0.10.3 spec/opal/core/source_map_spec.rb
opal-0.10.2 spec/opal/core/source_map_spec.rb
opal-0.10.1 spec/opal/core/source_map_spec.rb
opal-0.10.0 spec/opal/core/source_map_spec.rb
opal-0.10.0.rc2 spec/opal/core/source_map_spec.rb
opal-0.10.0.rc1 spec/opal/core/source_map_spec.rb
opal-0.10.0.beta5 spec/opal/core/source_map_spec.rb
opal-0.10.0.beta4 spec/opal/core/source_map_spec.rb
opal-0.10.0.beta3 spec/opal/core/source_map_spec.rb