<commit_before>require 'spec_helper'

RSpec.configure do |c|
  c.filter_run_excluding :broken => true
  c.filter_run_excluding :todo => true
end

describe Sprockets::Less do
  before :each do
    @root   = create_construct
    @assets = @root.directory 'assets'
    @env    = Sprockets::Environment.new @root.to_s
    @env.append_path @assets.to_s
  end

  after :each do
    @root.destroy!
  end

  it 'processes less files normally' do
    @assets.file 'main.css.less', '//= require dep'
    @assets.file 'dep.less', %(body { color: blue; })
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: blue;\n}\n"
  end

  it 'imports standard files' do
    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file 'dep.less', '@color: blue;'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports partials' do
    @assets.file 'main.css.less', %(@import "_dep";\nbody { color: @color; })
    @assets.file '_dep.less', '@color: blue;'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports files with the correct content type', :broken => true do
    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file 'dep.js', 'var app = {};'
    @assets.file '_dep.less', '@color: blue;'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports files with directives', :todo => true do
    @assets.file 'main.css.less', %(@import "dep";)
    @assets.file 'dep.css', "/*\n *= require subdep\n */"
    @assets.file 'subdep.css.less', "@color: blue;\nbody { color: @color; }"
    asset = @env['main.css']
    asset.to_s.should include("body {\n  color: #0000ff; }\n")
  end

  it 'imports files with additional processors', :todo => true do
    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file 'dep.css.less.erb', "@color: <%= 'blue' %>;"
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: blue; }\n"
  end

  it 'imports relative files', :todo => true do
    @assets.file 'folder/main.css.less', %(@import "./dep-1";\n@import "./subfolder/dep-2";\nbody { background-color: @background-color; color: @color; })
    @assets.file 'folder/dep-1.less', '@background-color: red;'
    @assets.file 'folder/subfolder/dep-2.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  background-color: #ff0000;\n  color: #0000ff; }\n"
  end

  it 'imports relative partials', :todo => true do
    @assets.file 'folder/main.css.less', %(@import "./dep-1";\n@import "./subfolder/dep-2";\nbody { background-color: @background-color; color: @color; })
    @assets.file 'folder/_dep-1.less', '@background-color: red;'
    @assets.file 'folder/subfolder/_dep-2.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  background-color: #ff0000;\n  color: blue; }\n"
  end

  it 'imports relative files without preceding ./', :todo => true do
    @assets.file 'folder/main.css.less', %(@import "dep-1";\n@import "subfolder/dep-2";\nbody { background-color: @background-color; color: @color; })
    @assets.file 'folder/dep-1.less', '@background-color: red;'
    @assets.file 'folder/subfolder/dep-2.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  background-color: red;\n  color: blue; }\n"
  end

  it 'imports relative partials without preceding ./', :todo => true do
    @assets.file 'folder/main.css.less', %(@import "dep-1";\n@import "subfolder/dep-2";\nbody { background-color: @background-color; color: @color; })
    @assets.file 'folder/_dep-1.less', '@background-color: red;'
    @assets.file 'folder/subfolder/_dep-2.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  background-color: red;\n  color: blue; }\n"
  end

  it 'imports files relative to root' do
    @assets.file 'folder/main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file 'dep.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports partials relative to root', :broken => true do
    @assets.file 'folder/main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file '_dep.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'shares Less environment with other imports' do
    @assets.file 'main.css.less', %(@import "dep-1";\n@import "dep-2";)
    @assets.file 'dep-1.less', '@color: blue;'
    @assets.file 'dep-2.less', 'body { color: @color; }'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports files from the assets load path' do
    vendor = @root.directory 'vendor'
    @env.append_path vendor.to_s

    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    vendor.file 'dep.less', '@color: blue;'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'allows global Less configuration' do
    Sprockets::Less.options[:compress] = true
    @assets.file 'main.css.less', "body {\n  color: #00f;\n}"

    asset = @env['main.css']
    asset.to_s.should == "body{color:#00f}\n"
    Sprockets::Less.options.delete(:compress)
  end

  it 'imports files from the Less load path' do
    vendor = @root.directory 'vendor'
    Sprockets::Less.options[:paths] = [ vendor.to_s ]

    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    vendor.file 'dep.less', '@color: blue;'<commit_msg>fix extra newlines in specs<commit_after>require 'spec_helper'

RSpec.configure do |c|
  c.filter_run_excluding :broken => true
  c.filter_run_excluding :todo => true
end

describe Sprockets::Less do
  before :each do
    @root   = create_construct
    @assets = @root.directory 'assets'
    @env    = Sprockets::Environment.new @root.to_s
    @env.append_path @assets.to_s
  end

  after :each do
    @root.destroy!
  end

  it 'processes less files normally' do
    @assets.file 'main.css.less', '//= require dep'
    @assets.file 'dep.less', %(body { color: blue; })
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: blue;\n}\n"
  end

  it 'imports standard files' do
    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file 'dep.less', '@color: blue;'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports partials' do
    @assets.file 'main.css.less', %(@import "_dep";\nbody { color: @color; })
    @assets.file '_dep.less', '@color: blue;'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports files with the correct content type', :broken => true do
    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file 'dep.js', 'var app = {};'
    @assets.file '_dep.less', '@color: blue;'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports files with directives', :todo => true do
    @assets.file 'main.css.less', %(@import "dep";)
    @assets.file 'dep.css', "/*\n *= require subdep\n */"
    @assets.file 'subdep.css.less', "@color: blue;\nbody { color: @color; }"
    asset = @env['main.css']
    asset.to_s.should include("body {\n  color: #0000ff; }\n")
  end

  it 'imports files with additional processors', :todo => true do
    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file 'dep.css.less.erb', "@color: <%= 'blue' %>;"
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: blue; }\n"
  end

  it 'imports relative files', :todo => true do
    @assets.file 'folder/main.css.less', %(@import "./dep-1";\n@import "./subfolder/dep-2";\nbody { background-color: @background-color; color: @color; })
    @assets.file 'folder/dep-1.less', '@background-color: red;'
    @assets.file 'folder/subfolder/dep-2.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  background-color: #ff0000;\n  color: #0000ff; }\n"
  end

  it 'imports relative partials', :todo => true do
    @assets.file 'folder/main.css.less', %(@import "./dep-1";\n@import "./subfolder/dep-2";\nbody { background-color: @background-color; color: @color; })
    @assets.file 'folder/_dep-1.less', '@background-color: red;'
    @assets.file 'folder/subfolder/_dep-2.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  background-color: #ff0000;\n  color: blue; }\n"
  end

  it 'imports relative files without preceding ./', :todo => true do
    @assets.file 'folder/main.css.less', %(@import "dep-1";\n@import "subfolder/dep-2";\nbody { background-color: @background-color; color: @color; })
    @assets.file 'folder/dep-1.less', '@background-color: red;'
    @assets.file 'folder/subfolder/dep-2.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  background-color: red;\n  color: blue; }\n"
  end

  it 'imports relative partials without preceding ./', :todo => true do
    @assets.file 'folder/main.css.less', %(@import "dep-1";\n@import "subfolder/dep-2";\nbody { background-color: @background-color; color: @color; })
    @assets.file 'folder/_dep-1.less', '@background-color: red;'
    @assets.file 'folder/subfolder/_dep-2.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  background-color: red;\n  color: blue; }\n"
  end

  it 'imports files relative to root' do
    @assets.file 'folder/main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file 'dep.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports partials relative to root', :broken => true do
    @assets.file 'folder/main.css.less', %(@import "dep";\nbody { color: @color; })
    @assets.file '_dep.less', '@color: blue;'
    asset = @env['folder/main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'shares Less environment with other imports' do
    @assets.file 'main.css.less', %(@import "dep-1";\n@import "dep-2";)
    @assets.file 'dep-1.less', '@color: blue;'
    @assets.file 'dep-2.less', 'body { color: @color; }'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'imports files from the assets load path' do
    vendor = @root.directory 'vendor'
    @env.append_path vendor.to_s

    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    vendor.file 'dep.less', '@color: blue;'
    asset = @env['main.css']
    asset.to_s.should == "body {\n  color: #0000ff;\n}\n"
  end

  it 'allows global Less configuration' do
    Sprockets::Less.options[:compress] = true
    @assets.file 'main.css.less', "body {\n  color: #00f;\n}"

    asset = @env['main.css']
    asset.to_s.should == "body{color:#00f}"
    Sprockets::Less.options.delete(:compress)
  end

  it 'imports files from the Less load path' do
    vendor = @root.directory 'vendor'
    Sprockets::Less.options[:paths] = [ vendor.to_s ]

    @assets.file 'main.css.less', %(@import "dep";\nbody { color: @color; })
    vendor.file 'dep.less', '@color: blue;'
{'fraction_non_alphanumeric': 0.19699078100539225, 'fraction_numerical': 0.011828144025047834, 'mean_word_length': 3.3490922844175492, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '1851704', 'n_tokens_mistral': 4309, 'n_tokens_neox': 4167, 'n_words': 997}