Esempio n. 1
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_font_face(self):
        src = """
            @font-face {
                    font-family: 'MyMinionPro';
                src: url('minion-webfont.eot?') format('eot'),
                    url('minion-webfont.woff') format('woff'),
                    url('minion-webfont.ttf') format('truetype');
                    font-weight: normal;
                    font-style: normal;
                    font-size: ( 12px / 16px ) * 100%;
            }

            @font-face {
                    font-family: 'MyMinionProItalic';
                src: url('minionpro-it-webfont.eot?') format('eot'),
                    url('minionpro-it-webfont.woff') format('woff'),
                    url('minionpro-it-webfont.ttf') format('truetype');
                    font-weight: normal;
                    font-style: italic;
            }

            h1,h2,h3, time, ol#using .number {
                    font-weight: normal;
                    font-family: 'MyMinionPro';
            }
        """
        test = "@font-face{font-weight:normal;font-style:normal;font-size:75%;font-family:'MyMinionPro';src:url('minion-webfont.eot?') format('eot') , url('minion-webfont.woff') format('woff') , url('minion-webfont.ttf') format('truetype')}@font-face{font-weight:normal;font-style:italic;font-family:'MyMinionProItalic';src:url('minionpro-it-webfont.eot?') format('eot') , url('minionpro-it-webfont.woff') format('woff') , url('minionpro-it-webfont.ttf') format('truetype')}h1, h2, h3, time, ol#using .number{font-weight:normal;font-family:'MyMinionPro'}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 2
0
class TestSCSS(unittest.TestCase):
    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_variables(self):
        src = """
            table.hl {
                margin: 2em 0;
                td.ln {
                    text-align: right;

                    li {
                        color: red;
                    }
                    &:hover {
                        width: 20px;
                    }
                }
            }

            li {
                font: {
                    family: serif;
                    weight: bold;
                    size: 1.2em;
                }
            }
            """
        test = "table.hl{margin:2em 0}table.hl td.ln{text-align:right}table.hl td.ln li{color:#f00}table.hl td.ln:hover{width:20px}li{font-weight:bold;font-size:1.2em;font-family:serif}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 3
0
class TestSCSS(unittest.TestCase):
    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_for(self):
        src = """
            @mixin test($src:2px){
                $width: $src + 5px;
                width: $width;
            }
            .test {
                color: blue;
                @for $i from 1 through 4 {
                    .span-#{$i}{
                        @include test($i); }
                }
            }

            @for $i from 1 through 2 {
                .span-#{$i}{
                    color: red; }
            }
        """
        test = ".test{color:#00f}.test .span-1{width:6px}.test .span-2{width:7px}.test .span-3{width:8px}.test .span-4{width:9px}.span-1{color:#f00}.span-2{color:#f00}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 4
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_for(self):
        src = """
            @mixin test($src:2px){
                $width: $src + 5px;
                width: $width;
            }
            .test {
                color: blue;
                @for $i from 1 through 4 {
                    .span-#{$i}{
                        @include test($i); }
                }
            }

            @for $i from 1 through 2 {
                .span-#{$i}{
                    color: red; }
            }
        """
        test = ".test{color:#00f}.test .span-1{width:6px}.test .span-2{width:7px}.test .span-3{width:8px}.test .span-4{width:9px}.span-1{color:#f00}.span-2{color:#f00}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 5
0
class TestSCSS(unittest.TestCase):
    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_font_face(self):
        src = """
            @font-face {
                    font-family: 'MyMinionPro';
                src: url('minion-webfont.eot?') format('eot'),
                    url('minion-webfont.woff') format('woff'),
                    url('minion-webfont.ttf') format('truetype');
                    font-weight: normal;
                    font-style: normal;
                    font-size: ( 12px / 16px ) * 100%;
            }

            @font-face {
                    font-family: 'MyMinionProItalic';
                src: url('minionpro-it-webfont.eot?') format('eot'),
                    url('minionpro-it-webfont.woff') format('woff'),
                    url('minionpro-it-webfont.ttf') format('truetype');
                    font-weight: normal;
                    font-style: italic;
            }

            h1,h2,h3, time, ol#using .number {
                    font-weight: normal;
                    font-family: 'MyMinionPro';
            }
        """
        test = "@font-face{font-weight:normal;font-style:normal;font-size:75%;font-family:'MyMinionPro';src:url('minion-webfont.eot?') format('eot') , url('minion-webfont.woff') format('woff') , url('minion-webfont.ttf') format('truetype')}@font-face{font-weight:normal;font-style:italic;font-family:'MyMinionProItalic';src:url('minionpro-it-webfont.eot?') format('eot') , url('minionpro-it-webfont.woff') format('woff') , url('minionpro-it-webfont.ttf') format('truetype')}h1, h2, h3, time, ol#using .number{font-weight:normal;font-family:'MyMinionPro'}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 6
0
class TestSCSS(unittest.TestCase):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_variables(self):
        src = """
            table.hl {
                margin: 2em 0;
                td.ln {
                    text-align: right;

                    li {
                        color: red;
                    }
                    &:hover {
                        width: 20px;
                    }
                }
            }

            li {
                font: {
                    family: serif;
                    weight: bold;
                    size: 1.2em;
                }
            }
            """
        test = "table.hl{margin:2em 0}table.hl td.ln{text-align:right}table.hl td.ln li{color:#f00}table.hl td.ln:hover{width:20px}li{font-weight:bold;font-size:1.2em;font-family:serif}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 7
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_math(self):
        src = """
           margin: 2px - 5em -1px 0;
        """
        test = ""
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 8
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_if(self):
        src = """
            $type: monster;
            $test: 9px;

            $rec: true;
            $rec2: $rec or true;
            $rec3: $rec or true;
            $rec: $rec2 or $rec3;

            @if $test + 2 > 10 {
                @if $rec {
                    .test { border: 2px; }
                }
            }

            @mixin test($fix: true) {
                @if $fix {
                    display: block;
                } @else {
                    display: none;
                }
            }
            span {
                @include test(false)
            }
            p {
                @if $type == girl {
                    color: pink;
                }
                @else if $type == monster {
                    color: red;
                    b { border: 2px; }
                }
                @else {
                    color: blue;
                }
            }
        """
        test = ".test{border:2px}span{display:none}p{color:#f00}p b{border:2px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 9
0
class TestSCSS(unittest.TestCase):
    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_if(self):
        src = """
            $type: monster;
            $test: 9px;

            $rec: true;
            $rec2: $rec or true;
            $rec3: $rec or true;
            $rec: $rec2 or $rec3;

            @if $test + 2 > 10 {
                @if $rec {
                    .test { border: 2px; }
                }
            }

            @mixin test($fix: true) {
                @if $fix {
                    display: block;
                } @else {
                    display: none;
                }
            }
            span {
                @include test(false)
            }
            p {
                @if $type == girl {
                    color: pink;
                }
                @else if $type == monster {
                    color: red;
                    b { border: 2px; }
                }
                @else {
                    color: blue;
                }
            }
        """
        test = ".test{border:2px}span{display:none}p{color:#f00}p b{border:2px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 10
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_variables(self):
        src = """
            @vars {
                $blue: #ffdd00 !default;
                $test: rgb(120, 35, 64);
                $test2: rgba(120, 35, 64, .4);
                $property: float;
                $value: left;
                $len: 0px or 5px;
            }
            $margin: 16px;
            $side: top;
            $image: 'test.png';

            .content-navigation {
                #{$property}: #{$value};
                border-color: $blue;
                background-color: $test + 5%;


                background-image: url('/test/' + $image);
                display: -moz-inline-box;
                color: $blue - 9%;
                margin: $len (-$margin * 2 ) -12px;
            }

            .border {
                padding-#{$side}: $margin / 2;
                margin: $margin / 2;
                padding-left: -$margin + 2px;
                border-#{$side}: {
                    color:  $blue;
                }
                color: $test2;
                font: -1.5em + 50px;
            }
            """
        test = ".content-navigation{float:left;display:-moz-inline-box;margin:5px -32px -12px;border-color:#fd0;background-color:#7b1f3e;background-image:url(/test/test.png);color:#f3d40b}.border{margin:8px;padding-top:8px;padding-left:-14px;border-top-color:#fd0;color:rgba(120,35,64,0.40);font:30.5px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 11
0
class TestSCSS(unittest.TestCase):
    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_variables(self):
        src = """
            @vars {
                $blue: #ffdd00 !default;
                $test: rgb(120, 35, 64);
                $test2: rgba(120, 35, 64, .4);
                $property: float;
                $value: left;
                $len: 0px or 5px;
            }
            $margin: 16px;
            $side: top;
            $image: 'test.png';

            .content-navigation {
                #{$property}: #{$value};
                border-color: $blue;
                background-color: $test + 5%;


                background-image: url('/test/' + $image);
                display: -moz-inline-box;
                color: $blue - 9%;
                margin: $len (-$margin * 2 ) -12px;
            }

            .border {
                padding-#{$side}: $margin / 2;
                margin: $margin / 2;
                padding-left: -$margin + 2px;
                border-#{$side}: {
                    color:  $blue;
                }
                color: $test2;
                font: -1.5em + 50px;
            }
            """
        test = ".content-navigation{float:left;display:-moz-inline-box;margin:5px -32px -12px;border-color:#fd0;background-color:#7b1f3e;background-image:url(/test/test.png);color:#f3d40b}.border{margin:8px;padding-top:8px;padding-left:-14px;border-top-color:#fd0;color:rgba(120,35,64,0.40);font:30.5px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 12
0
class TestSCSS(unittest.TestCase):
    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_extend(self):
        src = """
        .error {
            _border: 1px #f00;
            background-color: #fdd;
        }
        .error .intrusion {
            background-image: url("/image/hacked.png");
        }
        .seriousError {
            @extend .error;
            border-width: 3px;
        }
        """
        test = ".error, .seriousError{_border:1px #f00;background-color:#fdd}.error .intrusion, .seriousError .intrusion{background-image:url('/image/hacked.png')}.seriousError{border-width:3px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 13
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_extend(self):
        src = """
        .error {
            border: 1px #f00;
            background-color: #fdd;
        }
        .error .intrusion {
            background-image: url("/image/hacked.png");
        }
        .seriousError {
            @extend .error;
            border-width: 3px;
        }
        """
        test = ".error, .seriousError{border:1px #f00;background-color:#fdd}.error .intrusion, .seriousError .intrusion{background-image:url('/image/hacked.png')}.seriousError{border-width:3px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 14
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_mixin(self):
        src = """
        @mixin font {
            font: {
                weight: inherit;
                style: inherit;
                size: 100%;
                family: inherit; };
            vertical-align: baseline; }

        @mixin global {
            .global {
                border:red;
                @include font;
            }
        }

        @include global;

        @mixin rounded-top( $radius:10px ) {
            $side: top;
            border-#{$side}-radius: $radius;
            -moz-border-radius-#{$side}: $radius;
            -webkit-border-#{$side}-radius: $radius;
        }
        #navbar li { @include rounded-top; }
        #footer { @include rounded-top(5px); }
        """
        test = ".global{border:#f00;vertical-align:baseline;font-weight:inherit;font-style:inherit;font-size:100%;font-family:inherit}#navbar li{border-top-radius:10px;-moz-border-radius-top:10px;-webkit-border-top-radius:10px}#footer{border-top-radius:5px;-moz-border-radius-top:5px;-webkit-border-top-radius:5px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 15
0
 def setUp(self):
     self.parser = Stylesheet(options=dict(compress=True))
Esempio n. 16
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_bugs(self):
        src = """
            .bug {
                background: -webkit-gradient(linear, top left, 100% 100%, from(#ddd), to(#aaa));
                background: -moz-linear-gradient (top, #DDD, #AAA);
                margin: 2px -5em -1px 0;
            }
        """
        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)}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_base(self):
        src = """
            @charset utf-8;
            @import url(test);

            @warn "Test warnings!"
            @mixin z-base {
                a:hover, a:active { outline: none; }
                a, a:active, a:visited { color: #607890; }
                a:hover { color: #036; }
                @debug test; }

            @media print { @include z-base; }

            // Test comment
            /* Css comment */
            body:not(.test) {
                $font: Georgia;

                margin-bottom: .5em;
                font-family: $font, sans-serif;
                *font:13px/1.231 sans-serif; }

            ::selection {
                color: red;
            }

            .test:hover {
                color: red;
                &:after {
                    content: 'blue'; }}

            pre, code, kbd, samp {
                font: 12px/10px;
                font-family: monospace, sans-serif; }

            abbr[title], dfn[title] {
                border:2px; }

            """
        test = "@charset utf-8;\n@import url(test);\n@media print { a:hover, a:active{outline:none}a, a:active, a:visited{color:#607890}a:hover{color:#036} }body: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{content:#00f}pre, code, kbd, samp{font:12px / 10px;font-family:monospace , sans-serif}abbr[title], dfn[title]{border:2px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_nesting_2(self):
        src = """#navbar {
          width: 80%;
          height: 23px;
          ul { list-style-type: none; }
          li { float: left;
            a .test .main{ font-weight: bold; }
          } }"""
        test = "#navbar{width:80%;height:23px}#navbar ul{list-style-type:none}#navbar li{float:left}#navbar li a .test .main{font-weight:bold}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_nestproperties(self):
        src = """.fakeshadow {
            border: {
                style: solid;
                left: { width: 4px; color: #888; }
                right: { width: 2px; color: #ccc; }
            } }"""
        test = ".fakeshadow{border-style:solid;border-right-width:2px;border-right-color:#ccc;border-left-width:4px;border-left-color:#888}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_parent_references(self):
        src = """a { color: #ce4dd6;
            &:hover { color: #ffb3ff; }
            &:visited { color: #c458cb; }
            .test & { color: red; }}"""
        test = "a{color:#ce4dd6}a:hover{color:#ffb3ff}a:visited{color:#c458cb}.test a{color:#f00}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_variables(self):
        src = """$main-color: #ce4dd6;
            $style: solid;
            $def_test: first;
            $def_test: second;
            $def_test: beep-beep !default;
            #navbar { border-bottom: { color: $main-color; style: $style; } }
            a.#{$def_test} { color: $main-color; &:hover { border-bottom: $style 1px; } }"""
        test = "#navbar{border-bottom-style:solid;border-bottom-color:#ce4dd6}a.second{color:#ce4dd6}a.second:hover{border-bottom:solid 1px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_interpolation(self):
        src = """$side: top;
            $radius: 10px;
            div.rounded-#{$side} p {
            border-#{$side}-radius: $radius;
            -moz-border-radius-#{$side}: $radius;
            -webkit-border-#{$side}-radius: $radius; }"""
        test = "div.rounded-top p{border-top-radius:10px;-moz-border-radius-top:10px;-webkit-border-top-radius:10px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_mixin_arg(self):
        src = """@mixin rounded($side, $radius: 10px, $dummy: false) {
            border-#{$side}-radius: $radius;
            -moz-border-radius-#{$side}: $radius;
            -webkit-border-#{$side}-radius: $radius; }
            #navbar li { @include rounded(top); }
            #footer { @include rounded(top, 5px); }
            #sidebar { @include rounded(left, 8px); }"""
        test = "#navbar li{border-top-radius:10px;-moz-border-radius-top:10px;-webkit-border-top-radius:10px}#footer{border-top-radius:5px;-moz-border-radius-top:5px;-webkit-border-top-radius:5px}#sidebar{border-left-radius:8px;-moz-border-radius-left:8px;-webkit-border-left-radius:8px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_extend_rule(self):
        src = """
            .error { border: 1px #f00; background-color: #fdd; }
            a:hover {text-decoration: underline}
            .hoverlink {@extend a:hover}
            .error .intrusion { background-image: url(/image/hacked.png); }
            .seriousError { @extend .error; border-width: 3px; }
            """
        test = ".error, .seriousError{border:1px #f00;background-color:#fdd}a:hover{text-decoration:underline}.error .intrusion, .seriousError .intrusion{background-image:url(/image/hacked.png)}.seriousError{border-width:3px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 17
0
 def setUp(self):
     self.parser = Stylesheet()
Esempio n. 18
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet()

    def test_default(self):
        src = """
        @option compress:false;
        // SCSS comment
        /* CSS Comment */
        #navbar {
            height: 100px;
            color: #ff0033;
            border: 2px solid magenta;
            @warn "Test";

            li {
                background-color: red - #333;
                float: left;
                font: 8px/10px verdana;
                margin: 3px + 5.5px auto;
                height: 5px + (4px * 2);
            }
        }
        """
        test = "/* CSS Comment */\n#navbar {\n\theight: 100px;\n\tborder: 2px solid #f0f;\n\tcolor: #f03;}\n\n#navbar li {\n\tfloat: left;\n\tmargin: 8.5px auto;\n\theight: 13px;\n\tbackground-color: #c00;\n\tfont: 8px / 10px verdana;}\n\n"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_compress(self):
        src = """
        @option compress:true;
        // SCSS comment
        /* CSS Comment */
        #navbar, p {
            height: 100px;
            color: #ff0033;
            border: 2px solid magenta;

            li {
                background-color: red - #333;
                float: left;
                font: 8px/10px verdana;
                margin: 3px + 5.5px auto;
                height: 5px + (4px * 2);
            }
        }
        """
        test = "#navbar, p{height:100px;border:2px solid #f0f;color:#f03}#navbar li, p li{float:left;margin:8.5px auto;height:13px;background-color:#c00;font:8px / 10px verdana}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_comments(self):
        src = """
        @option comments:false, compress: false;
        // SCSS comment
        /* CSS Comment */
        #navbar, p {
            height: 100px;
            color: #ff0033;
            border: 2px solid magenta;

            li {
                background-color: red - #333;
                float: left;
                font: 8px/10px verdana;
                margin: 3px + 5.5px auto;
                height: 5px + (4px * 2);
            }
        }
        """
        test = "#navbar, p {\n\theight: 100px;\n\tborder: 2px solid #f0f;\n\tcolor: #f03;}\n\n#navbar li, p li {\n\tfloat: left;\n\tmargin: 8.5px auto;\n\theight: 13px;\n\tbackground-color: #c00;\n\tfont: 8px / 10px verdana;}\n\n"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_sortings(self):
        src = """
        @option comments:true, compress: false, sort: false;
        // SCSS comment
        /* CSS Comment */
        #navbar, p {
            height: 100px;
            color: #ff0033;
            border: 2px solid magenta;

            li {
                background-color: red - #333;
                float: left;
                font: 8px/10px verdana;
                margin: 3px + 5.5px auto;
                height: 5px + (4px * 2);
            }
        }
        """
        test = "/* CSS Comment */\n#navbar, p {\n\theight: 100px;\n\tcolor: #f03;\n\tborder: 2px solid #f0f;}\n\n#navbar li, p li {\n\tbackground-color: #c00;\n\tfloat: left;\n\tfont: 8px / 10px verdana;\n\tmargin: 8.5px auto;\n\theight: 13px;}\n\n"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 19
0
 def setUp(self):
     self.parser = Stylesheet(options=dict(compress=True))
Esempio n. 20
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_bugs(self):
        src = """
            .bug {
                background: -webkit-gradient(linear, top left, 100% 100%, from(#ddd), to(#aaa));
                background: -moz-linear-gradient (top, #DDD, #AAA);
                margin: 2px -5em -1px 0;
            }
        """
        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)}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_base(self):
        src = """
            @charset utf-8;
            @import url(test);

            @warn "Test warnings!"
            @mixin z-base {
                a:hover, a:active { outline: none; }
                a, a:active, a:visited { color: #607890; }
                a:hover { color: #036; }
                @debug test; }

            @media print { @include z-base; }

            // Test comment
            /* Css comment */
            body:not(.test) {
                $font: Georgia;

                margin-bottom: .5em;
                font-family: $font, sans-serif;
                *font:13px/1.231 sans-serif; }

            ::selection {
                color: red;
            }

            .test:hover {
                color: red;
                &:after {
                    content: 'blue'; }}

            pre, code, kbd, samp {
                font: 12px/10px;
                font-family: monospace, sans-serif; }

            abbr[title], dfn[title] {
                border:2px; }

            """
        test = "@charset utf-8;\n@import url(test);\n@media print { a:hover, a:active{outline:none}a, a:active, a:visited{color:#607890}a:hover{color:#036} }body:not(.test){margin-bottom:.5em;*font:13px / 1.231 sans-serif;font-family:Georgia , sans-serif}::selection{color:#f00}.test:hover{color:#f00}.test:hover:after{content:#00f}pre, code, kbd, samp{font:12px / 10px;font-family:monospace , sans-serif}abbr[title], dfn[title]{border:2px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_nesting_2(self):
        src = """#navbar {
          width: 80%;
          height: 23px;
          ul { list-style-type: none; }
          li { float: left;
            a .test .main{ font-weight: bold; }
          } }"""
        test = "#navbar{width:80%;height:23px}#navbar ul{list-style-type:none}#navbar li{float:left}#navbar li a .test .main{font-weight:bold}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_nestproperties(self):
        src = """.fakeshadow {
            border: {
                style: solid;
                left: { width: 4px; color: #888; }
                right: { width: 2px; color: #ccc; }
            } }"""
        test = ".fakeshadow{border-style:solid;border-right-width:2px;border-right-color:#ccc;border-left-width:4px;border-left-color:#888}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_parent_references(self):
        src = """a { color: #ce4dd6;
            &:hover { color: #ffb3ff; }
            &:visited { color: #c458cb; }
            .test & { color: red; }}"""
        test = "a{color:#ce4dd6}a:hover{color:#ffb3ff}a:visited{color:#c458cb}.test a{color:#f00}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_variables(self):
        src = """$main-color: #ce4dd6;
            $style: solid;
            $def_test: first;
            $def_test: second;
            $def_test: beep-beep !default;
            #navbar { border-bottom: { color: $main-color; style: $style; } }
            a.#{$def_test} { color: $main-color; &:hover { border-bottom: $style 1px; } }"""
        test = "#navbar{border-bottom-style:solid;border-bottom-color:#ce4dd6}a.second{color:#ce4dd6}a.second:hover{border-bottom:solid 1px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_interpolation(self):
        src = """$side: top;
            $radius: 10px;
            div.rounded-#{$side} p {
            border-#{$side}-radius: $radius;
            -moz-border-radius-#{$side}: $radius;
            -webkit-border-#{$side}-radius: $radius; }"""
        test = "div.rounded-top p{border-top-radius:10px;-moz-border-radius-top:10px;-webkit-border-top-radius:10px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_mixin_arg(self):
        src = """@mixin rounded($side, $radius: 10px, $dummy: false) {
            border-#{$side}-radius: $radius;
            -moz-border-radius-#{$side}: $radius;
            -webkit-border-#{$side}-radius: $radius; }
            #navbar li { @include rounded(top); }
            #footer { @include rounded(top, 5px); }
            #sidebar { @include rounded(left, 8px); }"""
        test = "#navbar li{border-top-radius:10px;-moz-border-radius-top:10px;-webkit-border-top-radius:10px}#footer{border-top-radius:5px;-moz-border-radius-top:5px;-webkit-border-top-radius:5px}#sidebar{border-left-radius:8px;-moz-border-radius-left:8px;-webkit-border-left-radius:8px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_extend_rule(self):
        src = """
            .error { border: 1px #f00; background-color: #fdd; }
            a:hover {text-decoration: underline}
            .hoverlink {@extend a:hover}
            .error .intrusion { background-image: url(/image/hacked.png); }
            .seriousError { @extend .error; border-width: 3px; }
            """
        test = ".error, .seriousError{border:1px #f00;background-color:#fdd}a:hover{text-decoration:underline}.error .intrusion, .seriousError .intrusion{background-image:url(/image/hacked.png)}.seriousError{border-width:3px}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 21
0
class TestSCSS( unittest.TestCase ):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_math(self):
        src = " 12 * (60px + 20px) "
        test = "960px"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_operations_and_functions(self):
        src = """
        #navbar {
            $navbar-width: 800px;
            $items: 1 + 2;
            $navbar-color: rgb(100, 100, 55);
            $font: "Verdana", monospace;
            width: $navbar-width;
            border-bottom: 2px solid $navbar-color;

            #{enumerate("div", 1, $items)} {
                p & {
                    color: blue }
                color: red; }
            }

            li {
                background-color: $navbar-color - #333;
                background-image: url(test/value.png);
                float: left;
                font: 8px/10px $font;
                margin: 3px + 5.5px auto;
                height: 5px + (4px * (2 + $items));
                width: $navbar-width / $items - 10px;
                &:hover { background-color: $navbar-color - 10%; } }"""
        test = "#navbar{width:800px;border-bottom:2px solid #646437}#navbar div1, #navbar div2, #navbar div3{color:#f00}p #navbar div1, p #navbar div2, p #navbar div3{color:#00f}li{float:left;margin:8.5px auto;width:256.667px;height:25px;background-color:#313104;background-image:url(test/value.png);font:8px / 10px 'Verdana', monospace}li:hover{background-color:#5c5c3e}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_rgb_functions(self):
        src = """
            @option warn:false;

            $color: rgba(23, 45, 67, .4)
            $color2: #fdc;
            .test {
                red_test: red($color);
                blue_test: blue($color);
                green_test: green($color);
                color: mix(#f00, #00f, 25%);
            }
        """
        test = ".test{color:#3f00bf;red_test:23;blue_test:67;green_test:45}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_hsl_functions(self):
        src = """
            @option warn:false;

            $hsl: hsla(0, 100%, 25%, .4);
            .test {
                color: $hsl;
                hue: hue($hsl);
                s: saturation($hsl);
                g: grayscale(#099);
                l: lighten(#333, 50%);
                ah: adjust-hue(#811, 45deg);
            }
        """
        test = ".test{color:rgba(127,0,0,0.40);hue:0;s:100%;g:#4c4c4c;l:#b2b2b2;ah:#886a10}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_opacity_functions(self):
        src = """
            $color: rgba(100, 100, 100, .4);
            .test {
                color: opacify( $color, 60% );
            }
        """
        test = ".test{color:#646464}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_string_functions(self):
        src = """
            $top: 'top';
            $bottom: bottom;
            .test {
                bottom: quote($bottom);
                top: unquote($top);
            }
        """
        test = ".test{top:top;bottom:'bottom'}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_number_functions(self):
        src = """
            @option warn:false;

            $top: 100px;
            $bottom: 50px;
            .test {
                top: percentage($top / $bottom);
                round: round($top);
                ceil: ceil(1.24);
                floor: floor(1.24);
                abs: abs(-1.24);
            }
        """
        test = ".test{top:200%;round:100.0;ceil:2.0;floor:1.0;abs:1.24}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_introspection_functions(self):
        src = """
            @option warn:false;

            $top: 100px;
            $color: #f00;
            .test {
                test: type-of($top);
                test2: type-of($color);
                test3: unit($top);
                test4: unitless($top);
            }
        """
        test = ".test{test:number;test2:color;test3:px;test4:false}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_compass_helpers(self):
        src = """
            #{append-selector(".foo, .bar", ".baz")} {
                color: red;
            }

            .example {

                #{elements-of-type(block)} {
                    border: 1px solid #777777;
                    margin: 1em 3em; }

                #{elements-of-type(inline)} {
                    color: #cc0000; }
            }

            a {
                #{headings(2, 4)} {
                    font-weight: bold;
                }
            }
        """
        test = ".foo .baz, .bar .baz{color:#f00}.example address, .example article, .example aside, .example blockquote, .example center, .example dd, .example dialog, .example dir, .example div, .example dl, .example dt, .example fieldset, .example figure, .example footer, .example form, .example frameset, .example h1, .example h2, .example h3, .example h4, .example h5, .example h6, .example header, .example hgroup, .example hr, .example isindex, .example menu, .example nav, .example noframes, .example noscript, .example ol, .example p, .example pre, .example section, .example ul{margin:1em 3em;border:1px solid #777}.example a, .example abbr, .example acronym, .example b, .example basefont, .example bdo, .example big, .example br, .example cite, .example code, .example dfn, .example em, .example font, .example i, .example img, .example input, .example kbd, .example label, .example q, .example s, .example samp, .example select, .example small, .example span, .example strike, .example strong, .example sub, .example sup, .example textarea, .example tt, .example u, .example var{color:#c00}a h2, a h3, a h4{font-weight:bold}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_image_functions(self):
        src = """
            img.test {
                width: image-width(scss/tests/ + 'bug_64.png');
                height: image-height(scss/tests/ + 'bug_64.png');
                background-image: inline-image(scss/tests/ + 'test.png')

            }
        """
        test = 'img.test{width:64px;height:64px;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAlQTFRF8EFB3AAA////d5xsogAAAAN0Uk5T//8A18oNQQAAAClJREFUeNpiYIIDBkYGCAXEYDaEAFEQKbAQVBEyE6EASRuSYQgrAAIMAB1mAIkfpDEtAAAAAElFTkSuQmCC")}'
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_function_define(self):
        src = """
            @function percent-width($t, $c) {
                $perc: $t / $c * 100%;
                @return $perc;
            }

            .test {
                width: percent-width(5px, 24px);
            }
        """
        test = ".test{width:20.833%}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_misc(self):
        src = """
            $test: center;
            .test {
                margin: 0 if($test == center, auto, 10px);
            }
        """
        test = ".test{margin:0 auto}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)
Esempio n. 22
0
class TestSCSS(unittest.TestCase):

    def setUp(self):
        self.parser = Stylesheet(options=dict(compress=True))

    def test_math(self):
        src = " 12 * (60px + 20px) "
        test = "960px"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_operations_and_functions(self):
        src = """
        #navbar {
            $navbar-width: 800px;
            $items: 1 + 2;
            $navbar-color: rgb(100, 100, 55);
            $font: "Verdana", monospace;
            width: $navbar-width;
            border-bottom: 2px solid $navbar-color;

            #{enumerate("div", 1, $items)} {
                p & {
                    color: blue }
                color: red; }
            }

            li {
                background-color: $navbar-color - #333;
                background-image: url(test/value.png);
                float: left;
                font: 8px/10px $font;
                margin: 3px + 5.5px auto;
                height: 5px + (4px * (2 + $items));
                width: $navbar-width / $items - 10px;
                &:hover { background-color: $navbar-color - 10%; } }"""
        test = "#navbar{width:800px;border-bottom:2px solid #646437}#navbar div1, #navbar div2, #navbar div3{color:#f00}p #navbar div1, p #navbar div2, p #navbar div3{color:#00f}li{float:left;margin:8.5px auto;width:256.667px;height:25px;background-color:#313104;background-image:url(test/value.png);font:8px / 10px 'Verdana', monospace}li:hover{background-color:#5c5c3e}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_rgb_functions(self):
        src = """
            @option warn:false;

            $color: rgba(23, 45, 67, .4)
            $color2: #fdc;
            .test {
                red_test: red($color);
                blue_test: blue($color);
                green_test: green($color);
                color: mix(#f00, #00f, 25%);
            }
        """
        test = ".test{color:#3f00bf;red_test:23;blue_test:67;green_test:45}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_hsl_functions(self):
        src = """
            @option warn:false;

            $hsl: hsla(0, 100%, 25%, .4);
            .test {
                color: $hsl;
                hue: hue($hsl);
                s: saturation($hsl);
                g: grayscale(#099);
                l: lighten(#333, 50%);
                ah: adjust-hue(#811, 45deg);
            }
        """
        test = ".test{color:rgba(127,0,0,0.40);hue:0;s:100%;g:#4c4c4c;l:#b2b2b2;ah:#886a10}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_opacity_functions(self):
        src = """
            $color: rgba(100, 100, 100, .4);
            .test {
                color: opacify( $color, 60% );
            }
        """
        test = ".test{color:#646464}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_string_functions(self):
        src = """
            $top: 'top';
            $bottom: bottom;
            .test {
                bottom: quote($bottom);
                top: unquote($top);
            }
        """
        test = ".test{top:top;bottom:'bottom'}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_number_functions(self):
        src = """
            @option warn:false;

            $top: 100px;
            $bottom: 50px;
            .test {
                top: percentage($top / $bottom);
                round: round($top);
                ceil: ceil(1.24);
                floor: floor(1.24);
                abs: abs(-1.24);
            }
        """
        test = ".test{top:200%;round:100.0;ceil:2.0;floor:1.0;abs:1.24}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_introspection_functions(self):
        src = """
            @option warn:false;

            $top: 100px;
            $color: #f00;
            .test {
                test: type-of($top);
                test2: type-of($color);
                test3: unit($top);
                test4: unitless($top);
            }
        """
        test = ".test{test:number;test2:color;test3:px;test4:false}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_compass_helpers(self):
        src = """
            #{append-selector(".foo, .bar", ".baz")} {
                color: red;
            }

            .example {

                #{elements-of-type(block)} {
                    border: 1px solid #777777;
                    margin: 1em 3em; }

                #{elements-of-type(inline)} {
                    color: #cc0000; }
            }

            a {
                #{headings(2, 4)} {
                    font-weight: bold;
                }
            }
        """
        test = ".foo .baz, .bar .baz{color:#f00}.example address, .example article, .example aside, .example blockquote, .example center, .example dd, .example dialog, .example dir, .example div, .example dl, .example dt, .example fieldset, .example figure, .example footer, .example form, .example frameset, .example h1, .example h2, .example h3, .example h4, .example h5, .example h6, .example header, .example hgroup, .example hr, .example isindex, .example menu, .example nav, .example noframes, .example noscript, .example ol, .example p, .example pre, .example section, .example ul{margin:1em 3em;border:1px solid #777}.example a, .example abbr, .example acronym, .example b, .example basefont, .example bdo, .example big, .example br, .example cite, .example code, .example dfn, .example em, .example font, .example i, .example img, .example input, .example kbd, .example label, .example q, .example s, .example samp, .example select, .example small, .example span, .example strike, .example strong, .example sub, .example sup, .example textarea, .example tt, .example u, .example var{color:#c00}a h2, a h3, a h4{font-weight:bold}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    @unittest.skipIf(not Image, 'PIL not found')
    def test_image_functions(self):
        src = """
            img.test {
                width: image-width(scss/tests/ + 'bug_64.png');
                height: image-height(scss/tests/ + 'bug_64.png');
                background-image: inline-image(scss/tests/ + 'test.png')

            }
        """
        test = 'img.test{width:64px;height:64px;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAlQTFRF8EFB3AAA////d5xsogAAAAN0Uk5T//8A18oNQQAAAClJREFUeNpiYIIDBkYGCAXEYDaEAFEQKbAQVBEyE6EASRuSYQgrAAIMAB1mAIkfpDEtAAAAAElFTkSuQmCC")}'
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_function_define(self):
        src = """
            @function percent-width($t, $c) {
                $perc: $t / $c * 100%;
                @return $perc;
            }

            .test {
                width: percent-width(5px, 24px);
            }
        """
        test = ".test{width:20.833%}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)

    def test_misc(self):
        src = """
            $test: center;
            .test {
                margin: 0 if($test == center, auto, 10px);
            }
        """
        test = ".test{margin:0 auto}"
        out = self.parser.loads(src)
        self.assertEqual(test, out)