#!/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 assert_sass_to_scss < true foo bar { baz: 12 $bang bip; } SCSS foo bar :baz= 12 $bang "bip" SASS 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 # Sass 3 Deprecation conversions def test_simple_quoted_strings_unquoted_with_equals assert_sass_to_scss '$var: 1px foo + bar baz;', '!var = 1px "foo" + "bar" baz' assert_sass_to_scss '$var: -foo-bar;', '!var = "-foo-bar"' end def test_complex_quoted_strings_explicitly_unquoted_with_equals assert_sass_to_scss '$var: 1px unquote("foo + bar") baz;', '!var = 1px "foo + bar" baz' assert_sass_to_scss "$var: unquote('foo\"bar');", '!var = "foo\"bar"' end def test_division_asserted_with_equals assert_sass_to_scss < 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_sass2_var_in_property_interpolation assert_sass_to_scss < :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'}k") 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 = {}) Haml::Util.silence_haml_warnings do Sass::Engine.new(scss, options).to_tree.to_sass(options) end end def to_scss(sass, options = {}) Haml::Util.silence_haml_warnings do Sass::Engine.new(sass, options).to_tree.to_scss(options) end end end