Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: test/declaration_test.dart

Issue 1407333002: Added beginning support for calc however, the expression is not fully parsed into the AST. (Closed) Base URL: https://github.com/dart-lang/csslib.git@master
Patch Set: Update CHANGELOG.md Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:test/test.dart'; 7 import 'package:test/test.dart';
8 8
9 import 'testing.dart'; 9 import 'testing.dart';
10 10
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 void testExpressionSpans() { 1008 void testExpressionSpans() {
1009 final input = r'''.foo { width: 50px; }'''; 1009 final input = r'''.foo { width: 50px; }''';
1010 var stylesheet = parseCss(input); 1010 var stylesheet = parseCss(input);
1011 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single; 1011 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single;
1012 // This passes 1012 // This passes
1013 expect(decl.span.text, 'width: 50px'); 1013 expect(decl.span.text, 'width: 50px');
1014 // This currently fails 1014 // This currently fails
1015 expect(decl.expression.span.text, '50px'); 1015 expect(decl.expression.span.text, '50px');
1016 } 1016 }
1017 1017
1018 void testDeclarationSpanWithCalc() { 1018 void simpleCalc() {
1019 final input = r'''.foo { height: calc(100% - 55px); }'''; 1019 final input = r'''.foo { height: calc(100% - 55px); }''';
1020 var stylesheet = parseCss(input); 1020 var stylesheet = parseCss(input);
1021 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single; 1021 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single;
1022 // This fails, with span being "height: calc(" 1022 expect(decl.span.text, 'height: calc(100% - 55px)');
1023 expect(decl.span.text, 'height: calc(100% - 55px);'); 1023 }
1024
1025 void complexCalc() {
1026 final input = r'''.foo { left: calc((100%/3 - 2) * 1em - 2 * 1px); }''';
1027 var stylesheet = parseCss(input);
1028 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single;
1029 expect(decl.span.text, 'left: calc((100%/3 - 2) * 1em - 2 * 1px)');
1030 }
1031
1032 void twoCalcs() {
1033 final input = r'''.foo { margin: calc(1rem - 2px) calc(1rem - 1px); }''';
1034 var stylesheet = parseCss(input);
1035 var decl = stylesheet.topLevels.single.declarationGroup.declarations.single;
1036 expect(decl.span.text, 'margin: calc(1rem - 2px) calc(1rem - 1px)');
1037 }
1038
1039 void selectorWithCalcs() {
1040 var errors = [];
1041 final String input = r'''
1042 .foo {
1043 width: calc(1em + 5 * 2em);
1044 height: calc(1px + 2%) !important;
1045 border: 5px calc(1pt + 2cm) 6px calc(1em + 1in + 2px) red;
1046 border: calc(5px + 1em) 0px 1px calc(10 + 20 + 1px);
1047 margin: 25px calc(50px + (100% / (3 - 1em) - 20%)) calc(10px + 10 * 20) calc(1 00% - 10px);
1048 }''';
1049 final String generated = r'''
1050 .foo {
1051 width: calc(1em + 5 * 2em);
1052 height: calc(1px + 2%) !important;
1053 border: 5px calc(1pt + 2cm) 6px calc(1em + 1in + 2px) #f00;
1054 border: calc(5px + 1em) 0px 1px calc(10 + 20 + 1px);
1055 margin: 25px calc(50px + (100% / (3 - 1em) - 20%)) calc(10px + 10 * 20) calc(1 00% - 10px);
1056 }''';
1057
1058 var stylesheet = parseCss(input, errors: errors);
1059 expect(stylesheet != null, true);
1060 expect(errors.isEmpty, true, reason: errors.toString());
1061 expect(prettyPrint(stylesheet), generated);
1024 } 1062 }
1025 1063
1026 main() { 1064 main() {
1027 test('Simple Terms', testSimpleTerms); 1065 test('Simple Terms', testSimpleTerms);
1028 test('Declarations', testDeclarations); 1066 test('Declarations', testDeclarations);
1029 test('Identifiers', testIdentifiers); 1067 test('Identifiers', testIdentifiers);
1030 test('Composites', testComposites); 1068 test('Composites', testComposites);
1031 test('Units', testUnits); 1069 test('Units', testUnits);
1032 test('Unicode', testUnicode); 1070 test('Unicode', testUnicode);
1033 test('Newer CSS', testNewerCss); 1071 test('Newer CSS', testNewerCss);
1034 test('Media Queries', testMediaQueries); 1072 test('Media Queries', testMediaQueries);
1035 test('Font-Face', testFontFace); 1073 test('Font-Face', testFontFace);
1036 test('CSS file', testCssFile); 1074 test('CSS file', testCssFile);
1037 test('Compact Emitter', testCompactEmitter); 1075 test('Compact Emitter', testCompactEmitter);
1038 test('Selector Negation', testNotSelectors); 1076 test('Selector Negation', testNotSelectors);
1039 test('IE stuff', testIE); 1077 test('IE stuff', testIE);
1040 test('IE declaration syntax', testIEDeclaration); 1078 test('IE declaration syntax', testIEDeclaration);
1041 test('Hanging bugs', testHangs); 1079 test('Hanging bugs', testHangs);
1042 test('Expression spans', testExpressionSpans, 1080 test('Expression spans', testExpressionSpans,
1043 skip: 'expression spans are broken' 1081 skip: 'expression spans are broken'
1044 ' (https://github.com/dart-lang/csslib/issues/15)'); 1082 ' (https://github.com/dart-lang/csslib/issues/15)');
1045 test('Declaration span containing calc()', testDeclarationSpanWithCalc, 1083 group('calc function', () {
1046 skip: 'calc() declarations are broken' 1084 test('simple calc', simpleCalc);
1047 ' (https://github.com/dart-lang/csslib/issues/17)'); 1085 test('single complex', complexCalc);
1086 test('two calc terms for same declaration', twoCalcs);
1087 test('selector with many calc declarations', selectorWithCalcs);
1088 });
1048 } 1089 }
1090
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698