mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Add tests for @extend, some of which are currently failing.
This commit is contained in:
parent
01795109ce
commit
f918cf3c39
1 changed files with 691 additions and 0 deletions
691
test/sass/extend_test.rb
Executable file
691
test/sass/extend_test.rb
Executable file
|
@ -0,0 +1,691 @@
|
|||
#!/usr/bin/env ruby
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class ConversionTest < Test::Unit::TestCase
|
||||
def test_basic
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo {a: b}
|
||||
.bar {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.bar {@extend .foo}
|
||||
.foo {a: b}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, .bar {
|
||||
a: b; }
|
||||
|
||||
.bar {
|
||||
c: d; }
|
||||
CSS
|
||||
.foo {a: b}
|
||||
.bar {c: d; @extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, .bar {
|
||||
a: b; }
|
||||
|
||||
.bar {
|
||||
c: d; }
|
||||
CSS
|
||||
.foo {a: b}
|
||||
.bar {@extend .foo; c: d}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_indented_syntax
|
||||
assert_equal <<CSS, render(<<SASS, :syntax => :sass)
|
||||
.foo, .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo
|
||||
a: b
|
||||
.bar
|
||||
@extend .foo
|
||||
SASS
|
||||
|
||||
assert_equal <<CSS, render(<<SASS, :syntax => :sass)
|
||||
.foo, .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo
|
||||
a: b
|
||||
.bar
|
||||
@extend \#{".foo"}
|
||||
SASS
|
||||
end
|
||||
|
||||
def test_multiple_targets
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, .bar {
|
||||
a: b; }
|
||||
|
||||
.blip .foo, .blip .bar {
|
||||
c: d; }
|
||||
CSS
|
||||
.foo {a: b}
|
||||
.bar {@extend .foo}
|
||||
.blip .foo {c: d}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_dynamic_extendee
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo {a: b}
|
||||
.bar {@extend \#{".foo"}}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
[baz^="blip12px"], .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
[baz^="blip12px"] {a: b}
|
||||
.bar {@extend [baz^="blip\#{12px}"]}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_nested_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo .bar, .foo .baz {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo .bar {a: b}
|
||||
.baz {@extend .bar}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_target_with_child
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo .bar, .baz .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo .bar {a: b}
|
||||
.baz {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_class_unification
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.bar, .bar.baz {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.bar {a: b}
|
||||
.baz {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.baz, .baz {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.baz {a: b}
|
||||
.baz {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_id_unification
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.bar, .bar#baz {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.bar {a: b}
|
||||
#baz {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo#baz, #baz {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo#baz {a: b}
|
||||
#baz {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo#baz {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo#baz {a: b}
|
||||
#bar {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_universal_unification_with_simple_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, * {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo {a: b}
|
||||
* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, *|* {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo {a: b}
|
||||
*|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.bar, .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.bar {a: b}
|
||||
* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.bar, .bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.bar {a: b}
|
||||
*|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.bar, ns|*.bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.bar {a: b}
|
||||
ns|* {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_universal_unification_with_namespaceless_universal_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*.foo, * {
|
||||
a: b; }
|
||||
CSS
|
||||
*.foo {a: b}
|
||||
* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*.foo, * {
|
||||
a: b; }
|
||||
CSS
|
||||
*.foo {a: b}
|
||||
*|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|*.foo, * {
|
||||
a: b; }
|
||||
CSS
|
||||
*|*.foo {a: b}
|
||||
* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|*.foo, *|* {
|
||||
a: b; }
|
||||
CSS
|
||||
*|*.foo {a: b}
|
||||
*|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*.foo, ns|* {
|
||||
a: b; }
|
||||
CSS
|
||||
*.foo {a: b}
|
||||
ns|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|*.foo, ns|* {
|
||||
a: b; }
|
||||
CSS
|
||||
*|*.foo {a: b}
|
||||
ns|* {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_universal_unification_with_namespaced_universal_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|*.foo, ns|* {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|*.foo {a: b}
|
||||
* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|*.foo, ns|* {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|*.foo {a: b}
|
||||
*|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns1|*.foo {
|
||||
a: b; }
|
||||
CSS
|
||||
ns1|*.foo {a: b}
|
||||
ns2|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|*.foo, ns|* {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|*.foo {a: b}
|
||||
ns|* {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_universal_unification_with_namespaceless_element_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
a.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
a.foo {a: b}
|
||||
* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
a.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
a.foo {a: b}
|
||||
*|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|a.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|a.foo {a: b}
|
||||
* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|a.foo, *|a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|a.foo {a: b}
|
||||
*|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
a.foo {a: b}
|
||||
ns|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|a.foo {a: b}
|
||||
ns|* {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_universal_unification_with_namespaced_element_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|a.foo {a: b}
|
||||
* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|a.foo {a: b}
|
||||
*|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns1|a.foo {
|
||||
a: b; }
|
||||
CSS
|
||||
ns1|a.foo {a: b}
|
||||
ns2|* {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|a.foo {a: b}
|
||||
ns|* {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_element_unification_with_simple_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo {a: b}
|
||||
a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.bar, a.bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.bar {a: b}
|
||||
a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.bar, *|a.bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.bar {a: b}
|
||||
*|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
.foo.bar, ns|a.bar {
|
||||
a: b; }
|
||||
CSS
|
||||
.foo.bar {a: b}
|
||||
ns|a {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_element_unification_with_namespaceless_universal_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
*.foo {a: b}
|
||||
a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
*.foo {a: b}
|
||||
*|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|*.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|*.foo {a: b}
|
||||
a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|*.foo, *|a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|*.foo {a: b}
|
||||
*|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
*.foo {a: b}
|
||||
ns|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|*.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|*.foo {a: b}
|
||||
ns|a {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_element_unification_with_namespaced_universal_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|*.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|*.foo {a: b}
|
||||
a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|*.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|*.foo {a: b}
|
||||
*|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns1|*.foo {
|
||||
a: b; }
|
||||
CSS
|
||||
ns1|*.foo {a: b}
|
||||
ns2|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|*.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|*.foo {a: b}
|
||||
ns|a {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_element_unification_with_namespaceless_element_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
a.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
a.foo {a: b}
|
||||
a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
a.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
a.foo {a: b}
|
||||
*|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|a.foo, a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|a.foo {a: b}
|
||||
a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|a.foo, *|a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|a.foo {a: b}
|
||||
*|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
a.foo {a: b}
|
||||
ns|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
*|a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
*|a.foo {a: b}
|
||||
ns|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
a.foo {
|
||||
a: b; }
|
||||
CSS
|
||||
a.foo {a: b}
|
||||
h1 {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_element_unification_with_namespaced_element_target
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|a.foo {a: b}
|
||||
a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|a.foo {a: b}
|
||||
*|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns1|a.foo {
|
||||
a: b; }
|
||||
CSS
|
||||
ns1|a.foo {a: b}
|
||||
ns2|a {@extend .foo}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
ns|a.foo, ns|a {
|
||||
a: b; }
|
||||
CSS
|
||||
ns|a.foo {a: b}
|
||||
ns|a {@extend .foo}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_attribute_unification
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
[foo=bar].baz, [foo=bar][foo=baz] {
|
||||
a: b; }
|
||||
CSS
|
||||
[foo=bar].baz {a: b}
|
||||
[foo=baz] {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
[foo=bar].baz, [foo=bar][foo^=bar] {
|
||||
a: b; }
|
||||
CSS
|
||||
[foo=bar].baz {a: b}
|
||||
[foo^=bar] {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
[foo=bar].baz, [foo=bar][foot=bar] {
|
||||
a: b; }
|
||||
CSS
|
||||
[foo=bar].baz {a: b}
|
||||
[foot=bar] {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
[foo=bar].baz, [foo=bar][ns|foo=bar] {
|
||||
a: b; }
|
||||
CSS
|
||||
[foo=bar].baz {a: b}
|
||||
[ns|foo=bar] {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
[foo=bar].baz, [foo=bar] {
|
||||
a: b; }
|
||||
CSS
|
||||
[foo=bar].baz {a: b}
|
||||
[foo=bar] {@extend .baz}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_pseudo_unification
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
:foo.baz, :foo:foo(2n+1) {
|
||||
a: b; }
|
||||
CSS
|
||||
:foo.baz {a: b}
|
||||
:foo(2n+1) {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
:foo.baz, :foo::foo {
|
||||
a: b; }
|
||||
CSS
|
||||
:foo.baz {a: b}
|
||||
::foo {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
:foo.baz, :foo:bar {
|
||||
a: b; }
|
||||
CSS
|
||||
:foo.baz {a: b}
|
||||
:bar {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
:foo.baz, :foo {
|
||||
a: b; }
|
||||
CSS
|
||||
:foo.baz {a: b}
|
||||
:foo {@extend .baz}
|
||||
SCSS
|
||||
end
|
||||
|
||||
def test_negation_unification
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
:not(.foo).baz, :not(.foo):not(.bar) {
|
||||
a: b; }
|
||||
CSS
|
||||
:not(.foo).baz {a: b}
|
||||
:not(.bar) {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
:not(.foo).baz, :not(.foo) {
|
||||
a: b; }
|
||||
CSS
|
||||
:not(.foo).baz {a: b}
|
||||
:not(.foo) {@extend .baz}
|
||||
SCSS
|
||||
|
||||
assert_equal <<CSS, render(<<SCSS)
|
||||
:not([a=b]).baz, :not([a=b]) {
|
||||
a: b; }
|
||||
CSS
|
||||
:not([a=b]).baz {a: b}
|
||||
:not([a = b]) {@extend .baz}
|
||||
SCSS
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render(sass, options = {})
|
||||
munge_filename options
|
||||
Sass::Engine.new(sass, {:syntax => :scss}.merge(options)).render
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue