<commit_before># frozen_string_literal: true
require 'sprockets_test'
require 'sprockets/bundle'
require 'sprockets/source_map_utils'

silence_warnings do
  require 'sass'
end

class TestSourceMaps < Sprockets::TestCase
  def setup
    @env = Sprockets::Environment.new(fixture_path('source-maps')) do |env|
      env.append_path('.')
      env.cache = {}
    end
  end

  def get_sources(map)
    map["sections"].reduce([]) { |r, s| r | s["map"]["sources"] }
  end

  # Offset should be the line that the asset starts on minus one
  test "correct offsets" do
    asset = @env["multi-require.js"]
    map   = asset.metadata[:map]

    child         = @env["child.js"]
    child_lines   = child.to_s.lines.length
    child_section = map["sections"][0]
    assert_equal 0, child_section["offset"]["line"]

    coffee_main         = @env["coffee/main.js"]
    coffee_main_lines   = coffee_main.to_s.lines.length
    coffee_main_section = map["sections"][1]
    assert_equal child_lines, coffee_main_section["offset"]["line"]

    sub_a_js          = @env["sub/a.js"]
    sub_a_js_lines    = sub_a_js.to_s.lines.length
    sub_a_js_section  = map["sections"][2]

    assert_equal coffee_main_lines + child_lines, sub_a_js_section["offset"]["line"]

    plain_js         = @env["plain.js"]
    plain_js_section = map["sections"][3]
    assert_equal sub_a_js_lines + coffee_main_lines + child_lines, plain_js_section["offset"]["line"]
  end<commit_msg>Ruby 2.5.1 warns about this<commit_after># frozen_string_literal: true
require 'sprockets_test'
require 'sprockets/bundle'
require 'sprockets/source_map_utils'

silence_warnings do
  require 'sass'
end

class TestSourceMaps < Sprockets::TestCase
  def setup
    @env = Sprockets::Environment.new(fixture_path('source-maps')) do |env|
      env.append_path('.')
      env.cache = {}
    end
  end

  def get_sources(map)
    map["sections"].reduce([]) { |r, s| r | s["map"]["sources"] }
  end

  # Offset should be the line that the asset starts on minus one
  test "correct offsets" do
    asset = @env["multi-require.js"]
    map   = asset.metadata[:map]

    child         = @env["child.js"]
    child_lines   = child.to_s.lines.length
    child_section = map["sections"][0]
    assert_equal 0, child_section["offset"]["line"]

    coffee_main         = @env["coffee/main.js"]
    coffee_main_lines   = coffee_main.to_s.lines.length
    coffee_main_section = map["sections"][1]
    assert_equal child_lines, coffee_main_section["offset"]["line"]

    sub_a_js          = @env["sub/a.js"]
    sub_a_js_lines    = sub_a_js.to_s.lines.length
    sub_a_js_section  = map["sections"][2]

    assert_equal coffee_main_lines + child_lines, sub_a_js_section["offset"]["line"]

    plain_js_section = map["sections"][3]
    assert_equal sub_a_js_lines + coffee_main_lines + child_lines, plain_js_section["offset"]["line"]
  end
{'fraction_non_alphanumeric': 0.1322400558269365, 'fraction_numerical': 0.0045359385903698535, 'mean_word_length': 3.8184873949579834, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7025151', 'n_tokens_mistral': 1015, 'n_tokens_neox': 1014, 'n_words': 187}