| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #library("declaration_tests"); | |
| 6 #import("../../css/css.dart"); | |
| 7 | |
| 8 void main() { | |
| 9 initCssWorld(); | |
| 10 | |
| 11 testSimpleTerms(); | |
| 12 testMoreDecls(); | |
| 13 testIdentifiers(); | |
| 14 testComposites(); | |
| 15 testNewerCss(); | |
| 16 testCssFile(); | |
| 17 } | |
| 18 | |
| 19 void testSimpleTerms() { | |
| 20 final String input = | |
| 21 ".foo {\n" + | |
| 22 " background-color: #191919;\n" + | |
| 23 " width: 10PX;\n" + | |
| 24 " height: 22mM !important;\n" + | |
| 25 " border-width: 20cm;\n" + | |
| 26 " margin-width: 33%;\n" + | |
| 27 " border-height: 30EM;\n" + | |
| 28 " width: .6in;\n" + | |
| 29 " length: 1.2in;\n" + | |
| 30 " -web-stuff: -10Px;\n" + | |
| 31 "}\n"; | |
| 32 final String generated = | |
| 33 "\n" + | |
| 34 ".foo {\n" + | |
| 35 " background-color: #191919;\n" + | |
| 36 " width: 10px;\n" + | |
| 37 " height: 22mm !important;\n" + | |
| 38 " border-width: 20cm;\n" + | |
| 39 " margin-width: 33%;\n" + | |
| 40 " border-height: 30em;\n" + | |
| 41 " width: .6in;\n" + // Check double values. | |
| 42 " length: 1.2in;\n" + | |
| 43 " -web-stuff: -10px;\n" + | |
| 44 "}\n"; | |
| 45 | |
| 46 Parser parser = | |
| 47 new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE, input)); | |
| 48 | |
| 49 Stylesheet stylesheet = parser.parse(); | |
| 50 Expect.isNotNull(stylesheet); | |
| 51 | |
| 52 Expect.equals(generated, stylesheet.toString()); | |
| 53 } | |
| 54 | |
| 55 void testMoreDecls() { | |
| 56 final String input = | |
| 57 ".more {\n" + | |
| 58 " color: red;\n" + | |
| 59 " color: #aabbcc; /* test -- 3 */\n" + | |
| 60 " color: blue;\n" + | |
| 61 " background-image: url(http://test.jpeg);\n" + | |
| 62 " background-image: url(\"http://double_quote.html\");\n" + | |
| 63 " background-image: url('http://single_quote.html');\n" + | |
| 64 " color: rgba(10,20,255); <!-- test CDO/CDC -->\n" + | |
| 65 " color: #123aef; /* hex # part integer and part identifier */\n" + | |
| 66 "}\n"; | |
| 67 final String generated = | |
| 68 "\n" + | |
| 69 ".more {\n" + | |
| 70 " color: #ff0000;\n" + | |
| 71 " color: #aabbcc;\n" + | |
| 72 " color: #0ff;\n" + | |
| 73 " background-image: url(http://test.jpeg);\n" + | |
| 74 " background-image: url(http://double_quote.html);\n" + | |
| 75 " background-image: url(http://single_quote.html);\n" + | |
| 76 " color: rgba(10, 20, 255);\n" + | |
| 77 " color: #123aef;\n" + | |
| 78 "}\n"; | |
| 79 | |
| 80 Parser parser = | |
| 81 new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE, input)); | |
| 82 | |
| 83 Stylesheet stylesheet = parser.parse(); | |
| 84 Expect.isNotNull(stylesheet); | |
| 85 | |
| 86 Expect.equals(generated, stylesheet.toString()); | |
| 87 } | |
| 88 | |
| 89 void testIdentifiers() { | |
| 90 final String input = | |
| 91 // Make sure identifiers that could look like hex are handled. | |
| 92 "#da {\n" + | |
| 93 " height: 100px;\n" + | |
| 94 "}\n" + | |
| 95 // Make sure elements that contain a leading dash (negative) are valid. | |
| 96 "#-foo {\n" + | |
| 97 " width: 10px;\n" + | |
| 98 " color: #ff00cc;\n" + | |
| 99 "}\n"; | |
| 100 final String generated = | |
| 101 "\n" + | |
| 102 "#da {\n" + | |
| 103 " height: 100px;\n" + | |
| 104 "}\n" + | |
| 105 "\n" + | |
| 106 "#-foo {\n" + | |
| 107 " width: 10px;\n" + | |
| 108 " color: #ff00cc;\n" + | |
| 109 "}\n"; | |
| 110 | |
| 111 Parser parser = | |
| 112 new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE, input)); | |
| 113 | |
| 114 Stylesheet stylesheet = parser.parse(); | |
| 115 Expect.isNotNull(stylesheet); | |
| 116 | |
| 117 Expect.equals(generated, stylesheet.toString()); | |
| 118 } | |
| 119 | |
| 120 void testComposites() { | |
| 121 final String input = | |
| 122 // Composites | |
| 123 ".xyzzy {\n" + | |
| 124 " border: 10px 80px 90px 100px;\n" + | |
| 125 " width: 99%;\n" + | |
| 126 "}\n" + | |
| 127 "@-webkit-keyframes pulsate {\n" + | |
| 128 " 0% {\n" + | |
| 129 " -webkit-transform: translate3d(0, 0, 0) scale(1.0);\n" + | |
| 130 " }\n" + | |
| 131 "}\n"; | |
| 132 final String generated = | |
| 133 "\n" + | |
| 134 ".xyzzy {\n" + | |
| 135 " border: 10px 80px 90px 100px;\n" + | |
| 136 " width: 99%;\n" + | |
| 137 "}\n" + | |
| 138 "@-webkit-keyframes pulsate {\n" + | |
| 139 " 0% {\n" + | |
| 140 " -webkit-transform: translate3d(0, 0, 0) scale(1.0);\n" + | |
| 141 " }\n" + | |
| 142 "}\n"; | |
| 143 Parser parser = | |
| 144 new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE, input)); | |
| 145 | |
| 146 Stylesheet stylesheet = parser.parse(); | |
| 147 Expect.isNotNull(stylesheet); | |
| 148 | |
| 149 Expect.equals(generated, stylesheet.toString()); | |
| 150 } | |
| 151 | |
| 152 void testNewerCss() { | |
| 153 final String input = | |
| 154 // Newer things in CSS | |
| 155 "@media screen,print {\n" + | |
| 156 " .foobar_screen {\n" + | |
| 157 " width: 10px;\n" + | |
| 158 " }\n" + | |
| 159 "}\n" + | |
| 160 "@page : test {\n" + | |
| 161 " width: 10px;\n" + | |
| 162 "}\n" + | |
| 163 "@page {\n" + | |
| 164 " height: 22px;\n" + | |
| 165 "}\n"; | |
| 166 final String generated = | |
| 167 "@media screen,print {\n" + | |
| 168 "\n" + | |
| 169 ".foobar_screen {\n" + | |
| 170 " width: 10px;\n" + | |
| 171 "}\n" + | |
| 172 "\n" + | |
| 173 "}\n" + | |
| 174 "@page : test {\n" + | |
| 175 " width: 10px;\n" + | |
| 176 "\n" + | |
| 177 "}\n" + | |
| 178 "@page {\n" + | |
| 179 " height: 22px;\n" + | |
| 180 "\n" + | |
| 181 "}\n"; | |
| 182 | |
| 183 Parser parser = | |
| 184 new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE, input)); | |
| 185 | |
| 186 Stylesheet stylesheet = parser.parse(); | |
| 187 Expect.isNotNull(stylesheet); | |
| 188 | |
| 189 Expect.equals(generated, stylesheet.toString()); | |
| 190 } | |
| 191 | |
| 192 void testCssFile() { | |
| 193 final String scss = | |
| 194 "@import 'simple.css'\n" + | |
| 195 "@import \"test.css\" print\n" + | |
| 196 "@import url(test.css) screen, print\n" + | |
| 197 | |
| 198 "div[href^='test'] {\n" + | |
| 199 " height: 10px;\n" + | |
| 200 "}\n" + | |
| 201 | |
| 202 "@-webkit-keyframes pulsate {\n" + | |
| 203 " from {\n" + | |
| 204 " -webkit-transform: translate3d(0, 0, 0) scale(1.0);\n" + | |
| 205 " }\n" + | |
| 206 " 10% {\n" + | |
| 207 " -webkit-transform: translate3d(0, 0, 0) scale(1.0);\n" + | |
| 208 " }\n" + | |
| 209 " 30% {\n" + | |
| 210 " -webkit-transform: translate3d(0, 2, 0) scale(1.0);\n" + | |
| 211 " }\n" + | |
| 212 "}\n" + | |
| 213 | |
| 214 ".foobar {\n" + | |
| 215 " grid-columns: 10px (\"content\" 1fr 10px)[4];\n" + | |
| 216 "}\n"; | |
| 217 | |
| 218 final String generated = | |
| 219 "@import url(simple.css)\n" + | |
| 220 "@import url(test.css) print\n" + | |
| 221 "@import url(test.css) screen,print\n" + | |
| 222 "\n" + | |
| 223 "div[href ^= \"test\"] {\n" + | |
| 224 " height: 10px;\n" + | |
| 225 "}\n" + | |
| 226 "@-webkit-keyframes pulsate {\n" + | |
| 227 " from {\n" + | |
| 228 " -webkit-transform: translate3d(0, 0, 0) scale(1.0);\n" + | |
| 229 " }\n" + | |
| 230 " 10% {\n" + | |
| 231 " -webkit-transform: translate3d(0, 0, 0) scale(1.0);\n" + | |
| 232 " }\n" + | |
| 233 " 30% {\n" + | |
| 234 " -webkit-transform: translate3d(0, 2, 0) scale(1.0);\n" + | |
| 235 " }\n" + | |
| 236 "}\n" + | |
| 237 "\n" + | |
| 238 ".foobar {\n" + | |
| 239 " grid-columns: 10px (\"content\" 1fr 10px) [4];\n" + | |
| 240 "}\n"; | |
| 241 | |
| 242 Parser parser = | |
| 243 new Parser(new SourceFile(SourceFile.IN_MEMORY_FILE, scss)); | |
| 244 | |
| 245 Stylesheet stylesheet = parser.parse(); | |
| 246 Expect.isNotNull(stylesheet); | |
| 247 | |
| 248 Expect.equals(generated, stylesheet.toString()); | |
| 249 } | |
| OLD | NEW |