gems.sass-3.2.8.test.sass.conversion_test.rb Maven / Gradle / Ivy
Go to download
Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rules, variables, mixins, selector
inheritance, and more. It's translated to well-formatted, standard CSS using the command line tool or a
web-framework plugin.
This is a repackaged GEM in a JAR format of the sass-lang.gem package. The sass-gems package version
follows the sass-lang.gem versions located http://rubyforge.org/frs/?group_id=9702. Simply change
the version of this package to download and repackage the same GEM version.
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../test_helper'
class ConversionTest < Test::Unit::TestCase
def test_basic
assert_renders < true
foo bar
:baz bang
:bip bop
SASS
foo bar {
baz: bang;
bip: bop;
}
SCSS
end
def test_empty_selector
assert_renders "foo bar", "foo bar {}"
end
def test_empty_directive
assert_scss_to_sass "@media screen", "@media screen {}"
assert_scss_to_scss "@media screen {}"
end
def test_empty_control_directive
assert_renders "@if false", "@if false {}"
end
def test_nesting
assert_renders < true
foo bar
:baz 12 $bang "bip"
SASS
foo bar {
baz: 12 $bang "bip";
}
SCSS
end
def test_multiline_properties
assert_scss_to_sass < true
foo
:_name val
:*name val
:#name val
:.name val
:name val
SASS
foo {
_name: val;
*name: val;
#name: val;
.name: val;
name: val;
}
SCSS
end
def test_selector_hacks
assert_selector_renders = lambda do |s|
assert_renders < E']
assert_selector_renders['+ E']
assert_selector_renders['~ E']
assert_selector_renders['> > E']
assert_selector_renders['E*']
assert_selector_renders['E*.foo']
assert_selector_renders['E*:hover']
end
def test_disallowed_colon_hack
assert_raise_message(Sass::SyntaxError, 'The ":name: val" hack is not allowed in the Sass indented syntax') do
to_sass("foo {:name: val;}", :syntax => :scss)
end
end
def test_nested_properties
assert_renders < true)
@mixin under-scored-mixin($under-scored-arg: $under-scored-default) {
bar: $under-scored-arg;
}
div {
foo: under-scored-fn($under-scored-var + "before\#{$another-under-scored-var}after");
@include under-scored-mixin($passed-arg);
selector-\#{$under-scored-interp}: bold;
}
@if $under-scored {
@for $for-var from $from-var to $to-var {
@while $while-var == true {
$while-var: false;
}
}
}
SCSS
=under_scored_mixin($under_scored_arg: $under_scored_default)
bar: $under_scored_arg
div
foo: under_scored_fn($under_scored_var + "before\#{$another_under_scored_var}after")
+under_scored_mixin($passed_arg)
selector-\#{$under_scored_interp}: bold
@if $under_scored
@for $for_var from $from_var to $to_var
@while $while_var == true
$while_var : false
SASS
end
def test_loud_comment_conversion
assert_renders(< " "
foo bar
baz bang
baz: bang
bip: bop
blat: boo
SASS
foo bar {
baz bang {
baz: bang;
bip: bop;
}
blat: boo;
}
SCSS
assert_renders < "\t"
foo bar
baz bang
baz: bang
bip: bop
blat: boo
SASS
foo bar {
baz bang {
baz: bang;
bip: bop;
}
blat: boo;
}
SCSS
assert_sass_to_scss < " "
foo bar {
baz bang {
baz: bang;
bip: bop;
}
blat: boo;
}
SCSS
foo bar
baz bang
baz: bang
bip: bop
blat: boo
SASS
assert_sass_to_scss < "\t"
foo bar {
baz bang {
baz: bang;
bip: bop;
}
blat: boo;
}
SCSS
foo bar
baz bang
baz: bang
bip: bop
blat: boo
SASS
assert_scss_to_sass < " "
foo bar
baz bang
baz: bang
bip: bop
blat: boo
SASS
foo bar {
baz bang {
baz: bang;
bip: bop;
}
blat: boo;
}
SCSS
assert_scss_to_sass < "\t"
foo bar
baz bang
baz: bang
bip: bop
blat: boo
SASS
foo bar {
baz bang {
baz: bang;
bip: bop;
}
blat: boo;
}
SCSS
end
def test_extend_with_optional
assert_scss_to_sass < ' ')
foo
// bar
/* baz
a: b
SASS
foo {
// bar
/* baz */
a: b;
}
SCSS
end
private
def assert_sass_to_sass(sass, options = {})
assert_equal(sass.rstrip, to_sass(sass, options).rstrip,
"Expected Sass to transform to itself")
end
def assert_scss_to_sass(sass, scss, options = {})
assert_equal(sass.rstrip, to_sass(scss, options.merge(:syntax => :scss)).rstrip,
"Expected SCSS to transform to Sass")
end
def assert_scss_to_scss(scss, in_scss = nil, options = nil)
if in_scss.is_a?(Hash)
options = in_scss
in_scss = nil
end
in_scss ||= scss
options ||= {}
assert_equal(scss.rstrip, to_scss(in_scss, options.merge(:syntax => :scss)).rstrip,
"Expected SCSS to transform to #{scss == in_scss ? 'itself' : 'SCSS'}")
end
def assert_sass_to_scss(scss, sass, options = {})
assert_equal(scss.rstrip, to_scss(sass, options).rstrip,
"Expected Sass to transform to SCSS")
end
def assert_renders(sass, scss, options = {})
assert_sass_to_sass(sass, options)
assert_scss_to_sass(sass, scss, options)
assert_scss_to_scss(scss, options)
assert_sass_to_scss(scss, sass, options)
end
def to_sass(scss, options = {})
Sass::Util.silence_sass_warnings do
Sass::Engine.new(scss, options).to_tree.to_sass(options)
end
end
def to_scss(sass, options = {})
Sass::Util.silence_sass_warnings do
Sass::Engine.new(sass, options).to_tree.to_scss(options)
end
end
end