2009-02-19 19:44:52 -08:00
|
|
|
require 'test/unit'
|
|
|
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
require 'sass/css'
|
|
|
|
|
|
|
|
class CSS2SassTest < Test::Unit::TestCase
|
|
|
|
def test_basic
|
|
|
|
css = <<CSS
|
|
|
|
h1 {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
assert_equal(<<SASS, css2sass(css))
|
|
|
|
h1
|
2009-06-19 02:57:01 -07:00
|
|
|
color: red
|
2009-02-19 19:44:52 -08:00
|
|
|
SASS
|
2009-06-19 02:57:01 -07:00
|
|
|
assert_equal(<<SASS, css2sass(css, :old => true))
|
2009-02-19 19:44:52 -08:00
|
|
|
h1
|
2009-06-19 02:57:01 -07:00
|
|
|
:color red
|
2009-02-19 19:44:52 -08:00
|
|
|
SASS
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_nesting
|
|
|
|
assert_equal(<<SASS, css2sass(<<CSS))
|
|
|
|
li
|
2009-06-19 02:57:01 -07:00
|
|
|
display: none
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
a
|
2009-06-19 02:57:01 -07:00
|
|
|
text-decoration: none
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
span
|
2009-06-19 02:57:01 -07:00
|
|
|
color: yellow
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
&:hover
|
2009-06-19 02:57:01 -07:00
|
|
|
text-decoration: underline
|
2009-02-19 19:44:52 -08:00
|
|
|
SASS
|
|
|
|
li {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
li a {
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
li a span {
|
|
|
|
color: yellow;
|
|
|
|
}
|
|
|
|
|
|
|
|
li a:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
2009-05-10 14:08:06 -07:00
|
|
|
def test_no_nesting_around_rules
|
|
|
|
assert_equal(<<SASS, css2sass(<<CSS))
|
|
|
|
div .warning
|
2009-06-19 02:57:01 -07:00
|
|
|
color: #d21a19
|
2009-05-10 14:08:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
span .debug
|
2009-06-19 02:57:01 -07:00
|
|
|
cursor: crosshair
|
2009-05-10 14:08:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
div .debug
|
2009-06-19 02:57:01 -07:00
|
|
|
cursor: default
|
2009-05-10 14:08:06 -07:00
|
|
|
SASS
|
|
|
|
div .warning {
|
|
|
|
color: #d21a19; }
|
|
|
|
span .debug {
|
|
|
|
cursor: crosshair;}
|
|
|
|
div .debug {
|
|
|
|
cursor: default; }
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
2009-02-19 19:44:52 -08:00
|
|
|
def test_comments_multiline
|
|
|
|
css = <<CSS
|
|
|
|
/* comment */
|
|
|
|
elephant.rawr {
|
|
|
|
rampages: excessively;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* actual multiline
|
|
|
|
comment */
|
|
|
|
span.turkey {
|
|
|
|
isdinner: true;
|
|
|
|
}
|
|
|
|
|
|
|
|
.turducken {
|
|
|
|
/* Sounds funny
|
|
|
|
doesn't it */
|
|
|
|
chimera: not_really;
|
|
|
|
}
|
|
|
|
|
|
|
|
#overhere {
|
|
|
|
bored: sorta; /* it's for a good
|
|
|
|
cause */
|
|
|
|
better_than: thread_pools;
|
|
|
|
}
|
|
|
|
|
|
|
|
#one_more {
|
|
|
|
finally: srsly;
|
|
|
|
} /* just a line here */
|
|
|
|
CSS
|
|
|
|
sass = <<SASS
|
|
|
|
elephant.rawr
|
2009-06-19 02:57:01 -07:00
|
|
|
rampages: excessively
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
|
|
|
|
span.turkey
|
2009-06-19 02:57:01 -07:00
|
|
|
isdinner: true
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
|
|
|
|
.turducken
|
2009-06-19 02:57:01 -07:00
|
|
|
chimera: not_really
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
|
|
|
|
#overhere
|
2009-06-19 02:57:01 -07:00
|
|
|
bored: sorta
|
|
|
|
better_than: thread_pools
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
|
|
|
|
#one_more
|
2009-06-19 02:57:01 -07:00
|
|
|
finally: srsly
|
2009-02-19 19:44:52 -08:00
|
|
|
SASS
|
|
|
|
assert_equal(css2sass(css), sass)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fold_commas
|
|
|
|
assert_equal(<<SASS, css2sass(<<CSS))
|
|
|
|
li
|
|
|
|
.one, .two
|
2009-06-19 02:57:01 -07:00
|
|
|
color: red
|
2009-02-19 19:44:52 -08:00
|
|
|
SASS
|
|
|
|
li .one {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
li .two {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
|
|
|
|
assert_equal(<<SASS, css2sass(<<CSS))
|
|
|
|
.one
|
2009-06-19 02:57:01 -07:00
|
|
|
color: green
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
|
|
|
|
.two
|
2009-06-19 02:57:01 -07:00
|
|
|
color: green
|
|
|
|
color: red
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
|
|
|
|
.three
|
2009-06-19 02:57:01 -07:00
|
|
|
color: red
|
2009-02-19 19:44:52 -08:00
|
|
|
SASS
|
|
|
|
.one, .two {
|
|
|
|
color: green;
|
|
|
|
}
|
|
|
|
|
|
|
|
.two, .three {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bad_formatting
|
|
|
|
assert_equal(<<SASS, css2sass(<<CSS))
|
|
|
|
hello
|
2009-06-19 02:57:01 -07:00
|
|
|
parent: true
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
there
|
2009-06-19 02:57:01 -07:00
|
|
|
parent: false
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
who
|
2009-06-19 02:57:01 -07:00
|
|
|
hoo: false
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
why
|
2009-06-19 02:57:01 -07:00
|
|
|
y: true
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
when
|
2009-06-19 02:57:01 -07:00
|
|
|
wen: nao
|
2009-02-19 19:44:52 -08:00
|
|
|
|
|
|
|
|
|
|
|
down_here
|
2009-06-19 02:57:01 -07:00
|
|
|
yeah: true
|
2009-02-19 19:44:52 -08:00
|
|
|
SASS
|
|
|
|
hello {
|
|
|
|
parent: true;
|
|
|
|
}
|
|
|
|
|
|
|
|
hello there {
|
|
|
|
parent: false;
|
|
|
|
}
|
|
|
|
hello who {
|
|
|
|
hoo: false;
|
|
|
|
}
|
|
|
|
hello why {
|
|
|
|
y: true;
|
|
|
|
}
|
|
|
|
hello when {
|
|
|
|
wen: nao;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
down_here { yeah: true; }
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
2009-06-27 21:58:20 -07:00
|
|
|
def test_comments_in_selectors
|
|
|
|
assert_equal(<<SASS, css2sass(<<CSS))
|
|
|
|
.js
|
|
|
|
#location-navigation-form .form-submit, #business-listing-form .form-submit, #detailTabs ul, #detailsEnhanced #addTags, #locationSearchList, #moreHoods
|
|
|
|
display: none
|
|
|
|
|
|
|
|
|
|
|
|
#navListLeft
|
|
|
|
display: none
|
|
|
|
SASS
|
|
|
|
.js #location-navigation-form .form-submit,
|
|
|
|
.js #business-listing-form .form-submit,
|
|
|
|
.js #detailTabs ul,
|
|
|
|
/* .js #addReview, */
|
|
|
|
/* .js #addTags, */
|
|
|
|
.js #detailsEnhanced #addTags,
|
|
|
|
.js #locationSearchList,
|
|
|
|
.js #moreHoods,
|
|
|
|
#navListLeft
|
|
|
|
{ display: none; }
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
2009-10-31 02:37:27 -07:00
|
|
|
def test_pseudo_classes_are_escaped
|
|
|
|
assert_equal(<<SASS, css2sass(<<CSS))
|
|
|
|
\\:focus
|
|
|
|
a: b
|
|
|
|
|
|
|
|
\\:foo
|
|
|
|
bar: baz
|
|
|
|
SASS
|
|
|
|
:focus {a: b;}
|
|
|
|
:focus :foo {bar: baz;}
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
2009-02-19 19:44:52 -08:00
|
|
|
private
|
|
|
|
|
|
|
|
def css2sass(string, opts={})
|
|
|
|
Sass::CSS.new(string, opts).render
|
|
|
|
end
|
|
|
|
end
|