#!/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_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) @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 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'}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