| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library declaration_test; | 5 library declaration_test; |
| 6 | 6 |
| 7 import 'package:csslib/src/messages.dart'; | 7 import 'package:csslib/src/messages.dart'; |
| 8 import 'package:csslib/visitor.dart'; | 8 import 'package:csslib/visitor.dart'; |
| 9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 10 | 10 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 css = '@media all AND (tranform-3d), (-webkit-transform-3d) {\n}'; | 471 css = '@media all AND (tranform-3d), (-webkit-transform-3d) {\n}'; |
| 472 expectCss(css, css); | 472 expectCss(css, css); |
| 473 | 473 |
| 474 // Test that AND operator is required between media type and expressions. | 474 // Test that AND operator is required between media type and expressions. |
| 475 css = '@media screen (min-device-width:400px'; | 475 css = '@media screen (min-device-width:400px'; |
| 476 stylesheet = parseCss(css, errors: errors..clear(), opts: simpleOptions); | 476 stylesheet = parseCss(css, errors: errors..clear(), opts: simpleOptions); |
| 477 expect(errors, isNotEmpty); | 477 expect(errors, isNotEmpty); |
| 478 expect( | 478 expect( |
| 479 errors.first.message, contains('expected { after media before ruleset')); | 479 errors.first.message, contains('expected { after media before ruleset')); |
| 480 expect(errors.first.span.text, '('); | 480 expect(errors.first.span.text, '('); |
| 481 |
| 482 // Test nested at-rules. |
| 483 input = ''' |
| 484 @media (min-width: 840px) { |
| 485 .cell { |
| 486 width: calc(33% - 16px); |
| 487 } |
| 488 @supports (display: grid) { |
| 489 .cell { |
| 490 grid-column-end: span 4; |
| 491 } |
| 492 } |
| 493 }'''; |
| 494 generated = '''@media (min-width:840px) { |
| 495 .cell { |
| 496 width: calc(33% - 16px); |
| 497 } |
| 498 @supports (display: grid) { |
| 499 .cell { |
| 500 grid-column-end: span 4; |
| 501 } |
| 502 } |
| 503 }'''; |
| 504 expectCss(input, generated); |
| 481 } | 505 } |
| 482 | 506 |
| 483 void testMozDocument() { | 507 void testMozDocument() { |
| 484 var errors = <Message>[]; | 508 var errors = <Message>[]; |
| 485 // Test empty url-prefix, commonly used for browser detection. | 509 // Test empty url-prefix, commonly used for browser detection. |
| 486 var css = ''' | 510 var css = ''' |
| 487 @-moz-document url-prefix() { | 511 @-moz-document url-prefix() { |
| 488 div { | 512 div { |
| 489 color: #000; | 513 color: #000; |
| 490 } | 514 } |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 var decl = (stylesheet.topLevels.single as RuleSet) | 1277 var decl = (stylesheet.topLevels.single as RuleSet) |
| 1254 .declarationGroup | 1278 .declarationGroup |
| 1255 .declarations | 1279 .declarations |
| 1256 .single; | 1280 .single; |
| 1257 // This passes | 1281 // This passes |
| 1258 expect(decl.span.text, 'width: 50px'); | 1282 expect(decl.span.text, 'width: 50px'); |
| 1259 // This currently fails | 1283 // This currently fails |
| 1260 expect((decl as Declaration).expression.span.text, '50px'); | 1284 expect((decl as Declaration).expression.span.text, '50px'); |
| 1261 } | 1285 } |
| 1262 | 1286 |
| 1287 void testComments() { |
| 1288 final css = '''/* This comment has a nested HTML comment... |
| 1289 * <html> |
| 1290 * <!-- Nested HTML comment... --> |
| 1291 * <div></div> |
| 1292 * </html> |
| 1293 */'''; |
| 1294 expectCss(css, ''); |
| 1295 } |
| 1296 |
| 1263 void simpleCalc() { | 1297 void simpleCalc() { |
| 1264 final input = r'''.foo { height: calc(100% - 55px); }'''; | 1298 final input = r'''.foo { height: calc(100% - 55px); }'''; |
| 1265 var stylesheet = parseCss(input); | 1299 var stylesheet = parseCss(input); |
| 1266 var decl = (stylesheet.topLevels.single as RuleSet) | 1300 var decl = (stylesheet.topLevels.single as RuleSet) |
| 1267 .declarationGroup | 1301 .declarationGroup |
| 1268 .declarations | 1302 .declarations |
| 1269 .single; | 1303 .single; |
| 1270 expect(decl.span.text, 'height: calc(100% - 55px)'); | 1304 expect(decl.span.text, 'height: calc(100% - 55px)'); |
| 1271 } | 1305 } |
| 1272 | 1306 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 test('Font-Face', testFontFace); | 1378 test('Font-Face', testFontFace); |
| 1345 test('CSS file', testCssFile); | 1379 test('CSS file', testCssFile); |
| 1346 test('Compact Emitter', testCompactEmitter); | 1380 test('Compact Emitter', testCompactEmitter); |
| 1347 test('Selector Negation', testNotSelectors); | 1381 test('Selector Negation', testNotSelectors); |
| 1348 test('IE stuff', testIE); | 1382 test('IE stuff', testIE); |
| 1349 test('IE declaration syntax', testIEDeclaration); | 1383 test('IE declaration syntax', testIEDeclaration); |
| 1350 test('Hanging bugs', testHangs); | 1384 test('Hanging bugs', testHangs); |
| 1351 test('Expression spans', testExpressionSpans, | 1385 test('Expression spans', testExpressionSpans, |
| 1352 skip: 'expression spans are broken' | 1386 skip: 'expression spans are broken' |
| 1353 ' (https://github.com/dart-lang/csslib/issues/15)'); | 1387 ' (https://github.com/dart-lang/csslib/issues/15)'); |
| 1388 test('Comments', testComments); |
| 1354 group('calc function', () { | 1389 group('calc function', () { |
| 1355 test('simple calc', simpleCalc); | 1390 test('simple calc', simpleCalc); |
| 1356 test('single complex', complexCalc); | 1391 test('single complex', complexCalc); |
| 1357 test('two calc terms for same declaration', twoCalcs); | 1392 test('two calc terms for same declaration', twoCalcs); |
| 1358 test('selector with many calc declarations', selectorWithCalcs); | 1393 test('selector with many calc declarations', selectorWithCalcs); |
| 1359 test('vendor prefixed calc', vendorPrefixedCalc); | 1394 test('vendor prefixed calc', vendorPrefixedCalc); |
| 1360 }); | 1395 }); |
| 1361 } | 1396 } |
| OLD | NEW |