| OLD | NEW |
| (Empty) |
| 1 import unittest | |
| 2 | |
| 3 from scss.parser import Stylesheet | |
| 4 | |
| 5 | |
| 6 class TestSCSS( unittest.TestCase ): | |
| 7 | |
| 8 def setUp(self): | |
| 9 self.parser = Stylesheet(options=dict(compress=True)) | |
| 10 | |
| 11 def test_bugs(self): | |
| 12 src = """ | |
| 13 .bug { | |
| 14 background: -webkit-gradient(linear, top left, 100% 100%, from(#
ddd), to(#aaa)); | |
| 15 background: -moz-linear-gradient (top, #DDD, #AAA); | |
| 16 margin: 2px -5em -1px 0; | |
| 17 } | |
| 18 """ | |
| 19 test = ".bug{margin:2px -5em -1px 0;background:-webkit-gradient(linear,
top left, 100% 100%, from(#ddd), to(#aaa));background:-moz-linear-gradient(top,
#ddd, #aaa)}" | |
| 20 out = self.parser.loads(src) | |
| 21 self.assertEqual(test, out) | |
| 22 | |
| 23 def test_base(self): | |
| 24 src = """ | |
| 25 @charset utf-8; | |
| 26 @import url(test); | |
| 27 | |
| 28 @warn "Test warnings!" | |
| 29 @mixin z-base { | |
| 30 a:hover, a:active { outline: none; } | |
| 31 a, a:active, a:visited { color: #607890; } | |
| 32 a:hover { color: #036; } | |
| 33 @debug test; } | |
| 34 | |
| 35 @media print { @include z-base; } | |
| 36 | |
| 37 // Test comment | |
| 38 /* Css comment */ | |
| 39 body:not(.test) { | |
| 40 $font: Georgia; | |
| 41 | |
| 42 margin-bottom: .5em; | |
| 43 font-family: $font, sans-serif; | |
| 44 *font:13px/1.231 sans-serif; } | |
| 45 | |
| 46 ::selection { | |
| 47 color: red; | |
| 48 } | |
| 49 | |
| 50 .test:hover { | |
| 51 color: red; | |
| 52 &:after { | |
| 53 content: 'blue'; }} | |
| 54 | |
| 55 pre, code, kbd, samp { | |
| 56 font: 12px/10px; | |
| 57 font-family: monospace, sans-serif; } | |
| 58 | |
| 59 abbr[title], dfn[title] { | |
| 60 border:2px; } | |
| 61 | |
| 62 """ | |
| 63 test = "@charset utf-8;\n@import url(test);\n@media print { a:hover, a:a
ctive{outline:none}a, a:active, a:visited{color:#607890}a:hover{color:#036} }bod
y:not(.test){margin-bottom:.5em;font-family:Georgia , sans-serif;*font:13px / 1.
231 sans-serif}::selection{color:#f00}.test:hover{color:#f00}.test:hover:after{c
ontent:#00f}pre, code, kbd, samp{font:12px / 10px;font-family:monospace , sans-s
erif}abbr[title], dfn[title]{border:2px}" | |
| 64 out = self.parser.loads(src) | |
| 65 self.assertEqual(test, out) | |
| 66 | |
| 67 def test_nesting_2(self): | |
| 68 src = """#navbar { | |
| 69 width: 80%; | |
| 70 height: 23px; | |
| 71 ul { list-style-type: none; } | |
| 72 li { float: left; | |
| 73 a .test .main{ font-weight: bold; } | |
| 74 } }""" | |
| 75 test = "#navbar{width:80%;height:23px}#navbar ul{list-style-type:none}#n
avbar li{float:left}#navbar li a .test .main{font-weight:bold}" | |
| 76 out = self.parser.loads(src) | |
| 77 self.assertEqual(test, out) | |
| 78 | |
| 79 def test_nestproperties(self): | |
| 80 src = """.fakeshadow { | |
| 81 border: { | |
| 82 style: solid; | |
| 83 left: { width: 4px; color: #888; } | |
| 84 right: { width: 2px; color: #ccc; } | |
| 85 } }""" | |
| 86 test = ".fakeshadow{border-style:solid;border-right-width:2px;border-rig
ht-color:#ccc;border-left-width:4px;border-left-color:#888}" | |
| 87 out = self.parser.loads(src) | |
| 88 self.assertEqual(test, out) | |
| 89 | |
| 90 def test_parent_references(self): | |
| 91 src = """a { color: #ce4dd6; | |
| 92 &:hover { color: #ffb3ff; } | |
| 93 &:visited { color: #c458cb; } | |
| 94 .test & { color: red; }}""" | |
| 95 test = "a{color:#ce4dd6}a:hover{color:#ffb3ff}a:visited{color:#c458cb}.t
est a{color:#f00}" | |
| 96 out = self.parser.loads(src) | |
| 97 self.assertEqual(test, out) | |
| 98 | |
| 99 def test_variables(self): | |
| 100 src = """$main-color: #ce4dd6; | |
| 101 $style: solid; | |
| 102 $def_test: first; | |
| 103 $def_test: second; | |
| 104 $def_test: beep-beep !default; | |
| 105 #navbar { border-bottom: { color: $main-color; style: $style; } } | |
| 106 a.#{$def_test} { color: $main-color; &:hover { border-bottom: $style
1px; } }""" | |
| 107 test = "#navbar{border-bottom-style:solid;border-bottom-color:#ce4dd6}a.
second{color:#ce4dd6}a.second:hover{border-bottom:solid 1px}" | |
| 108 out = self.parser.loads(src) | |
| 109 self.assertEqual(test, out) | |
| 110 | |
| 111 def test_interpolation(self): | |
| 112 src = """$side: top; | |
| 113 $radius: 10px; | |
| 114 div.rounded-#{$side} p { | |
| 115 border-#{$side}-radius: $radius; | |
| 116 -moz-border-radius-#{$side}: $radius; | |
| 117 -webkit-border-#{$side}-radius: $radius; }""" | |
| 118 test = "div.rounded-top p{border-top-radius:10px;-moz-border-radius-top:
10px;-webkit-border-top-radius:10px}" | |
| 119 out = self.parser.loads(src) | |
| 120 self.assertEqual(test, out) | |
| 121 | |
| 122 def test_mixin_arg(self): | |
| 123 src = """@mixin rounded($side, $radius: 10px, $dummy: false) { | |
| 124 border-#{$side}-radius: $radius; | |
| 125 -moz-border-radius-#{$side}: $radius; | |
| 126 -webkit-border-#{$side}-radius: $radius; } | |
| 127 #navbar li { @include rounded(top); } | |
| 128 #footer { @include rounded(top, 5px); } | |
| 129 #sidebar { @include rounded(left, 8px); }""" | |
| 130 test = "#navbar li{border-top-radius:10px;-moz-border-radius-top:10px;-w
ebkit-border-top-radius:10px}#footer{border-top-radius:5px;-moz-border-radius-to
p:5px;-webkit-border-top-radius:5px}#sidebar{border-left-radius:8px;-moz-border-
radius-left:8px;-webkit-border-left-radius:8px}" | |
| 131 out = self.parser.loads(src) | |
| 132 self.assertEqual(test, out) | |
| 133 | |
| 134 def test_extend_rule(self): | |
| 135 src = """ | |
| 136 .error { border: 1px #f00; background-color: #fdd; } | |
| 137 a:hover {text-decoration: underline} | |
| 138 .hoverlink {@extend a:hover} | |
| 139 .error .intrusion { background-image: url(/image/hacked.png); } | |
| 140 .seriousError { @extend .error; border-width: 3px; } | |
| 141 """ | |
| 142 test = ".error, .seriousError{border:1px #f00;background-color:#fdd}a:ho
ver{text-decoration:underline}.error .intrusion, .seriousError .intrusion{backgr
ound-image:url(/image/hacked.png)}.seriousError{border-width:3px}" | |
| 143 out = self.parser.loads(src) | |
| 144 self.assertEqual(test, out) | |
| OLD | NEW |