#!/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.34568", 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" end def test_null assert_renders "null" end def test_empty_list assert_renders "()" end def test_list_in_args assert_renders "foo((a, b, c))" assert_renders "foo($arg: (a, b, c))" assert_renders "foo(a, b, (a, b, c)...)" end def test_map assert_renders "(foo: bar)" assert_renders "(foo: bar, baz: bip)" assert_renders "(foo: bar, baz: (bip: bap))" end def test_map_in_list assert_renders "(foo: bar) baz" assert_renders "(foo: bar), (baz: bip)" end def test_list_in_map assert_renders "(foo: bar baz)" assert_renders "(foo: (bar, baz), bip: bop)" end def self.test_precedence(outer, inner) op_outer = Sass::Script::Lexer::OPERATORS_REVERSE[outer] op_inner = Sass::Script::Lexer::OPERATORS_REVERSE[inner] class_eval <