<commit_before>require 'sprockets_test'
require 'shared_sass_tests'

silence_warnings do
  require 'sassc'
end

require 'sprockets/sassc_processor'
require 'sprockets/sassc_compressor'

class TestBaseSassc < Sprockets::TestCase
  CACHE_PATH = File.expand_path("../../.sass-cache", __FILE__)

  def sass
    ::SassC
  end

  def sass_functions
    ::SassC::Script::Functions
  end

  def sass_engine
    ::SassC::Engine
  end

  def syntax_error
    SassC::SyntaxError
  end

  def compressor
    Sprockets::SasscCompressor
  end

  def teardown
    refute ::SassC::Script::Functions.instance_methods.include?(:asset_path)
    FileUtils.rm_r(CACHE_PATH) if File.exist?(CACHE_PATH)
    assert !File.exist?(CACHE_PATH)
  end
end

class TestNoSassFunctionSassC < TestBaseSassc
  module ::SassC::Script::Functions
    def javascript_path(path)
      ::SassC::Script::String.new("/js/#{path.value}", :string)
    end

    module Compass
      def stylesheet_path(path)
        ::SassC::Script::String.new("/css/#{path.value}", :string)
      end
    end
    include Compass
  end

  include SharedSassTestNoFunction
end

class TestSprocketsSassc < TestBaseSassc
  def setup
    super

    @env = Sprockets::Environment.new(".") do |env|
      env.cache = {}
      env.append_path(fixture_path('.'))
      env.append_path(fixture_path('compass'))
      env.append_path(fixture_path('octicons'))
      env.register_transformer 'text/sass', 'text/css', Sprockets::SasscProcessor.new
    end
  end

  def teardown
    assert !File.exist?(CACHE_PATH)
  end

  def render(path)
    path = fixture_path(path)
    silence_warnings do
      @env.find_asset(path, accept: 'text/css').to_s
    end
  end

  test "raise sass error with line number" do
    begin
      ::Sass::Util.silence_sass_warnings do
        render('sass/error.sass')
      end
      flunk
    rescue SassC::SyntaxError => error
      # this is not exactly consistent with ruby sass
      assert error.message.include?("invalid")
      assert error.message.include?("error.sass")
      assert error.message.include?("line 5")
    end
  end

  test "track sass dependencies metadata" do
    skip "not consistent with ruby sass"

    asset = nil
    silence_warnings do
      asset = @env.find_asset('sass/import_partial.css')
    end
    assert asset
    assert_equal [
      fixture_path('sass/_rounded.scss'),
      fixture_path('sass/import_partial.sass')
    ], asset.metadata[:sass_dependencies].to_a.sort
  end

  include SharedSassTestSprockets
end

class TestSasscCompressor < TestBaseSassc
  include SharedSassTestCompressor
end

class TestSasscFunctions < TestSprocketsSassc
  def setup
    super
    define_asset_path
  end

  def define_asset_path
    @env.context_class.class_eval do
      def asset_path(path, options = {})
        link_asset(path)
        "/#{path}"
      end
    end
  end

  include SharedSassTestFunctions
end
<commit_msg>remove warning silence for sassc<commit_after>require 'sprockets_test'
require 'shared_sass_tests'

silence_warnings do
  require 'sassc'
end

require 'sprockets/sassc_processor'
require 'sprockets/sassc_compressor'

class TestBaseSassc < Sprockets::TestCase
  CACHE_PATH = File.expand_path("../../.sass-cache", __FILE__)

  def sass
    ::SassC
  end

  def sass_functions
    ::SassC::Script::Functions
  end

  def sass_engine
    ::SassC::Engine
  end

  def syntax_error
    SassC::SyntaxError
  end

  def compressor
    Sprockets::SasscCompressor
  end

  def teardown
    refute ::SassC::Script::Functions.instance_methods.include?(:asset_path)
    FileUtils.rm_r(CACHE_PATH) if File.exist?(CACHE_PATH)
    assert !File.exist?(CACHE_PATH)
  end
end

class TestNoSassFunctionSassC < TestBaseSassc
  module ::SassC::Script::Functions
    def javascript_path(path)
      ::SassC::Script::String.new("/js/#{path.value}", :string)
    end

    module Compass
      def stylesheet_path(path)
        ::SassC::Script::String.new("/css/#{path.value}", :string)
      end
    end
    include Compass
  end

  include SharedSassTestNoFunction
end

class TestSprocketsSassc < TestBaseSassc
  def setup
    super

    @env = Sprockets::Environment.new(".") do |env|
      env.cache = {}
      env.append_path(fixture_path('.'))
      env.append_path(fixture_path('compass'))
      env.append_path(fixture_path('octicons'))
      env.register_transformer 'text/sass', 'text/css', Sprockets::SasscProcessor.new
    end
  end

  def teardown
    assert !File.exist?(CACHE_PATH)
  end

  def render(path)
    path = fixture_path(path)
    silence_warnings do
      @env.find_asset(path, accept: 'text/css').to_s
    end
  end

  test "raise sass error with line number" do
    begin
      render('sass/error.sass')
      flunk
    rescue SassC::SyntaxError => error
      # this is not exactly consistent with ruby sass
      assert error.message.include?("invalid")
      assert error.message.include?("error.sass")
      assert error.message.include?("line 5")
    end
  end

  test "track sass dependencies metadata" do
    skip "not consistent with ruby sass"

    asset = nil
    silence_warnings do
      asset = @env.find_asset('sass/import_partial.css')
    end
    assert asset
    assert_equal [
      fixture_path('sass/_rounded.scss'),
      fixture_path('sass/import_partial.sass')
    ], asset.metadata[:sass_dependencies].to_a.sort
  end

  include SharedSassTestSprockets
end

class TestSasscCompressor < TestBaseSassc
  include SharedSassTestCompressor
end

class TestSasscFunctions < TestSprocketsSassc
  def setup
    super
    define_asset_path
  end

  def define_asset_path
    @env.context_class.class_eval do
      def asset_path(path, options = {})
        link_asset(path)
        "/#{path}"
      end
    end
  end

  include SharedSassTestFunctions
end

{'fraction_non_alphanumeric': 0.09873767940515303, 'fraction_numerical': 0.0003458412588621823, 'mean_word_length': 3.3718820861678003, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '2085565', 'n_tokens_mistral': 2009, 'n_tokens_neox': 1962, 'n_words': 405}