#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../test_helper' class ExtendTest < Test::Unit::TestCase def test_basic assert_equal < :sass) .foo, .bar { a: b; } CSS .foo a: b .bar @extend .foo SASS assert_equal < :sass) .foo, .bar { a: b; } CSS .foo a: b .bar @extend \#{".foo"} SASS end def test_multiple_targets assert_equal < bar { a: b; } CSS .baz .foo {a: b} foo > bar {@extend .foo} SCSS end def test_nested_extender_finds_common_selectors_around_child_selector assert_equal < b c .c1, a > b c .c2 { a: b; } CSS a > b c .c1 {a: b} a c .c2 {@extend .c1} SCSS assert_equal < b c .c1, a > b c .c2 { a: b; } CSS a > b c .c1 {a: b} b c .c2 {@extend .c1} SCSS end def test_nested_extender_doesnt_find_common_selectors_around_adjacent_sibling_selector assert_equal < .bap .foo, .bip > .bap .grip > .bap .bar, .grip > .bap .bip > .bap .bar { a: b; } CSS .bip > .bap .foo {a: b} .grip > .bap .bar {@extend .foo} SCSS assert_equal < .bip .foo, .bap > .bip .bap > .grip .bar, .bap > .grip .bap > .bip .bar { a: b; } CSS .bap > .bip .foo {a: b} .bap > .grip .bar {@extend .foo} SCSS end def test_nested_extender_with_child_selector_unifies assert_equal < bar.baz { a: b; } CSS .baz.foo {a: b} foo > bar {@extend .foo} SCSS end def test_nested_extender_with_trailing_child_selector assert_raise(Sass::SyntaxError, "bar > can't extend: invalid selector") do render("bar > {@extend .baz}") end end def test_nested_extender_with_sibling_selector assert_equal < > + bar { a: b; } CSS .baz .foo {a: b} foo + > > + bar {@extend .foo} SCSS assert_equal < > bar { a: b; } CSS .baz .foo {a: b} > > bar {@extend .foo} SCSS end def test_nested_extender_merges_with_same_selector assert_equal < .bar .baz, .foo > .bar .bang { a: b; } CSS .foo > .bar .baz {a: b} .foo > .bar .bang {@extend .baz} SCSS end # Loops def test_extend_self_loop assert_equal < .foo, > foo bar { a: b; } CSS > .foo {a: b} foo bar {@extend .foo} SCSS end def test_nested_selector_with_child_selector_hack_extender assert_equal < .foo foo bar, > foo .foo bar { a: b; } CSS .foo .bar {a: b} > foo bar {@extend .bar} SCSS end def test_nested_selector_with_child_selector_hack_extender_and_extendee assert_equal < .foo, > foo bar { a: b; } CSS > .foo {a: b} > foo bar {@extend .foo} SCSS end def test_nested_selector_with_child_selector_hack_extender_and_sibling_selector_extendee assert_equal < foo bar {@extend .foo} SCSS end def test_nested_selector_with_child_selector_hack_extender_and_extendee_and_newline assert_equal < .foo, > flip, > foo bar { a: b; } CSS > .foo {a: b} flip, > foo bar {@extend .foo} SCSS end private def render(sass, options = {}) munge_filename options Sass::Engine.new(sass, {:syntax => :scss}.merge(options)).render end end