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

Unified Diff: packages/csslib/test/visitor_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/csslib/test/var_test.dart ('k') | packages/dart_style/._.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/csslib/test/visitor_test.dart
diff --git a/packages/csslib/test/visitor_test.dart b/packages/csslib/test/visitor_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..803b10614738b509fbed3c24453db98da81c7ad9
--- /dev/null
+++ b/packages/csslib/test/visitor_test.dart
@@ -0,0 +1,113 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library visitor_test;
+
+import 'package:csslib/visitor.dart';
+import 'package:test/test.dart';
+
+import 'testing.dart';
+
+class ClassVisitor extends Visitor {
+ final List expectedClasses;
+ final Set<String> foundClasses = new Set();
+
+ ClassVisitor(this.expectedClasses);
+
+ void visitClassSelector(ClassSelector node) {
+ foundClasses.add(node.name);
+ }
+
+ bool get matches {
+ bool match = true;
+ foundClasses.forEach((value) {
+ match = match && expectedClasses.contains(value);
+ });
+ expectedClasses.forEach((value) {
+ match = match && foundClasses.contains(value);
+ });
+
+ return match;
+ }
+}
+
+void testClassVisitors() {
+ var errors = [];
+ var in1 = '.foobar { }';
+
+ var s = parseCss(in1, errors: errors);
+
+ expect(s != null, true);
+ expect(errors.isEmpty, true, reason: errors.toString());
+
+ var clsVisits = new ClassVisitor(['foobar'])..visitTree(s);
+ expect(clsVisits.matches, true);
+
+ in1 = '''
+ .foobar1 { }
+ .xyzzy .foo #my-div { color: red; }
+ div.hello { font: arial; }
+ ''';
+
+ s = parseCss(in1, errors: errors..clear(), opts: simpleOptions);
+
+ expect(s != null, true);
+ expect(errors.isEmpty, true, reason: errors.toString());
+
+ clsVisits = new ClassVisitor(['foobar1', 'xyzzy', 'foo', 'hello'])
+ ..visitTree(s);
+ expect(clsVisits.matches, true);
+
+ expect(prettyPrint(s), r'''
+.foobar1 {
+}
+.xyzzy .foo #my-div {
+ color: #f00;
+}
+div.hello {
+ font: arial;
+}''');
+}
+
+class PolyfillEmitter extends CssPrinter {
+ final String _prefix;
+
+ PolyfillEmitter(this._prefix);
+
+ void visitClassSelector(ClassSelector node) {
+ emit('.${_prefix}_${node.name}');
+ }
+}
+
+String polyfillPrint(String prefix, StyleSheet ss) =>
+ (new PolyfillEmitter(prefix)..visitTree(ss, pretty: true)).toString();
+
+void testPolyFill() {
+ var errors = [];
+ final input = r'''
+.foobar { }
+div.xyzzy { }
+#foo .foo .bar .foobar { }
+''';
+
+ final generated = r'''
+.myComponent_foobar {
+}
+div.myComponent_xyzzy {
+}
+#foo .myComponent_foo .myComponent_bar .myComponent_foobar {
+}''';
+
+ var s = parseCss(input, errors: errors);
+ expect(s != null, true);
+ expect(errors.isEmpty, true, reason: errors.toString());
+
+ final emitted = polyfillPrint('myComponent', s);
+ expect(emitted, generated);
+}
+
+main() {
+ test('Class Visitors', testClassVisitors);
+ test('Polyfill', testPolyFill);
+}
« no previous file with comments | « packages/csslib/test/var_test.dart ('k') | packages/dart_style/._.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698