#!/usr/bin/env ruby # -*- coding: utf-8 -*- require File.dirname(__FILE__) + '/../test_helper' require 'sass/engine' class SassScriptConversionTest < Test::Unit::TestCase def test_bool assert_renders "true" assert_renders "false" end def test_color assert_renders "#abcdef" assert_renders "blue" assert_renders "rgba(0, 1, 2, 0.2)" assert_equal "#aabbcc", render("#abc") assert_equal "blue", render("#0000ff") end def test_number assert_renders "10" assert_renders "10.35" assert_renders "12px" assert_renders "12.45px" assert_equal "12.346", render("12.345678901") end def test_string assert_renders '"foo"' assert_renders '"bar baz"' assert_equal '"baz bang"', render("'baz bang'") end def test_string_quotes assert_equal "'quote\"quote'", render('"quote\\"quote"') assert_equal '"quote\'quote"', render("'quote\\'quote'") assert_renders '"quote\'quote\\"quote"' assert_equal '"quote\'quote\\"quote"', render("'quote\\'quote\"quote'") end def test_string_escapes assert_renders '"foo\\\\bar"' end def test_funcall assert_renders "foo(true, blue)" assert_renders "hsla(20deg, 30%, 50%, 0.3)" assert_renders "blam()" assert_renders "-\xC3\xBFoo(12px)" assert_renders "-foo(12px)" end def test_funcall_with_keyword_args assert_renders "foo(arg1, arg2, $karg1: val, $karg2: val2)" assert_renders "foo($karg1: val, $karg2: val2)" end def test_url assert_renders "url(foo.gif)" assert_renders "url($var)" assert_renders "url(\#{$var}/flip.gif)" end def test_variable assert_renders "$foo-bar" assert_renders "$flaznicate" assert_warning(< :equals) assert_equal '#{$bar}baz', render('"#{$bar}baz"', :context => :equals) assert_equal 'foo#{$bar}', render('"foo#{$bar}"', :context => :equals) assert_equal 'unquote(".foo#{$bar}.bar")', render('".foo#{$bar}.bar"', :context => :equals) assert_equal 'unquote(".foo#{$bar}")', render('".foo#{$bar}"', :context => :equals) assert_equal 'unquote("#{$bar}.bar")', render('"#{$bar}.bar"', :context => :equals) assert_equal "unquote(\"f'o\#{$bar}b'z\")", render("'f\\'o\#{$bar}b\\'z'", :context => :equals) assert_equal "unquote('f\"o\#{$bar}b\"z')", render("'f\\\"o\#{$bar}b\\\"z'", :context => :equals) assert_equal "unquote(\"f'o\#{$bar}b\\\"z\")", render("'f\\'o\#{$bar}b\\\"z'", :context => :equals) end def test_sass2_urls Sass::Util.silence_sass_warnings do assert_equal 'url(foo/bar.gif)', render('url(foo/bar.gif)', :context => :equals) assert_equal 'url("foo/bar.gif")', render('url("foo/bar.gif")', :context => :equals) assert_equal 'url($var)', render('url(!var)', :context => :equals) assert_equal 'url("#{$var}/flip.gif")', render('url("#{!var}/flip.gif")', :context => :equals) end end private def assert_renders(script, options = {}) assert_equal(script, render(script, options)) end def render(script, options = {}) munge_filename(options) node = Sass::Script.parse(script, 1, 0, options) node.context = options[:context] if options[:context] node.to_sass end end