#!/usr/bin/env ruby # -*- coding: utf-8 -*- require File.dirname(__FILE__) + '/test_helper' class ScssTest < Test::Unit::TestCase include ScssTestHelper ## One-Line Comments def test_one_line_comments assert_equal < e assert_equal < e assert_equal "Undefined mixin 'bar'.", e.message assert_equal 3, e.sass_line end def test_rules_beneath_properties render < e assert_equal 'Illegal nesting: Only properties may be nested beneath properties.', e.message assert_equal 3, e.sass_line end def test_uses_property_exception_with_star_hack render < e assert_equal 'Invalid CSS after " *bar:baz ": expected ";", was "[fail]; }"', e.message assert_equal 2, e.sass_line end def test_uses_property_exception_with_colon_hack render < e assert_equal 'Invalid CSS after " :bar:baz ": expected ";", was "[fail]; }"', e.message assert_equal 2, e.sass_line end def test_uses_rule_exception_with_dot_hack render <; } SCSS assert(false, "Expected syntax error") rescue Sass::SyntaxError => e assert_equal 'Invalid CSS after " .bar:baz ": expected "{", was "; }"', e.message assert_equal 2, e.sass_line end def test_uses_property_exception_with_space_after_name render < e assert_equal 'Invalid CSS after " bar: baz ": expected ";", was "[fail]; }"', e.message assert_equal 2, e.sass_line end def test_uses_property_exception_with_non_identifier_after_name render < e assert_equal 'Invalid CSS after " bar:1px ": expected ";", was "[fail]; }"', e.message assert_equal 2, e.sass_line end def test_uses_property_exception_when_followed_by_open_bracket render < e assert_equal 'Invalid CSS after " bar:{baz: ": expected expression (e.g. 1px, bold), was ".fail} }"', e.message assert_equal 2, e.sass_line end def test_script_error render < e assert_equal 'Invalid CSS after " bar: "baz" * ": expected expression (e.g. 1px, bold), was "* }"', e.message assert_equal 2, e.sass_line end def test_multiline_script_syntax_error render < e assert_equal 'Invalid CSS after " "baz" * ": expected expression (e.g. 1px, bold), was "* }"', e.message assert_equal 3, e.sass_line end def test_multiline_script_runtime_error render < e assert_equal "Undefined variable: \"$bang\".", e.message assert_equal 4, e.sass_line end def test_post_multiline_script_runtime_error render < e assert_equal "Undefined variable: \"$bop\".", e.message assert_equal 5, e.sass_line end def test_multiline_property_runtime_error render < e assert_equal "Undefined variable: \"$bang\".", e.message assert_equal 4, e.sass_line end def test_post_resolution_selector_error render "\n\nfoo \#{\") bar\"} {a: b}" assert(false, "Expected syntax error") rescue Sass::SyntaxError => e assert_equal 'Invalid CSS after "foo ": expected selector, was ") bar"', e.message assert_equal 3, e.sass_line end def test_parent_in_mid_selector_error assert_raise_message(Sass::SyntaxError, < :nested)) .foo { @fblthp { .bar { a: b; } } } CSS .foo { @fblthp { .bar {a: b} } } SCSS assert_equal(< :compressed)) .foo{@fblthp{.bar{a:b}}} CSS .foo { @fblthp { .bar {a: b} } } SCSS assert_equal(< :compact)) .foo { @fblthp { .bar { a: b; } } } CSS .foo { @fblthp { .bar {a: b} } } SCSS assert_equal(< :expanded)) .foo { @fblthp { .bar { a: b; } } } CSS .foo { @fblthp { .bar {a: b} } } SCSS end def test_loud_comment_in_compressed_mode assert_equal(< :compressed) z a,z b{display:block} CSS a , b { z & { display: block; } } SCSS end def test_if_error_line assert_raise_line(2) {render(< :compressed) foo{color:#000} CSS foo {color: darken(black, 10%)} SCSS end # ref: https://github.com/nex3/sass/issues/104 def test_no_buffer_overflow template = render <