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

Unified Diff: pkg/csslib/test/selector_test.dart

Issue 23168002: move csslib into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | « pkg/csslib/test/run_all.dart ('k') | pkg/csslib/test/testing.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/csslib/test/selector_test.dart
diff --git a/pkg/csslib/test/selector_test.dart b/pkg/csslib/test/selector_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ad015bb5715f714f5b62326b23a3f21d3e0b92a2
--- /dev/null
+++ b/pkg/csslib/test/selector_test.dart
@@ -0,0 +1,67 @@
+// Copyright (c) 2012, 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 selector_test;
+
+import 'package:unittest/unittest.dart';
+import 'testing.dart';
+import 'package:csslib/parser.dart';
+import 'package:csslib/visitor.dart';
+
+void testSelectorSuccesses() {
+ var errors = [];
+ var selectorAst = selector('#div .foo', errors: errors);
+ expect(errors.isEmpty, true, reason: errors.toString());
+ expect('#div .foo', compactOuptut(selectorAst));
+
+ // Valid selectors for class names.
+ selectorAst = selector('.foo', errors: errors..clear());
+ expect(errors.isEmpty, true, reason: errors.toString());
+ expect('.foo', compactOuptut(selectorAst));
+
+ selectorAst = selector('.foobar .xyzzy', errors: errors..clear());
+ expect(errors.isEmpty, true, reason: errors.toString());
+ expect('.foobar .xyzzy', compactOuptut(selectorAst));
+
+ selectorAst = selector('.foobar .a-story .xyzzy', errors: errors..clear());
+ expect(errors.isEmpty, true, reason: errors.toString());
+ expect('.foobar .a-story .xyzzy', compactOuptut(selectorAst));
+
+ selectorAst = selector('.foobar .xyzzy .a-story .b-story',
+ errors: errors..clear());
+ expect(errors.isEmpty, true, reason: errors.toString());
+ expect('.foobar .xyzzy .a-story .b-story', compactOuptut(selectorAst));
+
+ // Valid selectors for element IDs.
+ selectorAst = selector('#id1', errors: errors..clear());
+ expect(errors.isEmpty, true, reason: errors.toString());
+ expect('#id1', compactOuptut(selectorAst));
+
+ selectorAst = selector('#id-number-3', errors: errors..clear());
+ expect(errors.isEmpty, true, reason: errors.toString());
+ expect('#id-number-3', compactOuptut(selectorAst));
+
+ selectorAst = selector('#_privateId', errors: errors..clear());
+ expect(errors.isEmpty, true, reason: errors.toString());
+ expect('#_privateId', compactOuptut(selectorAst));
+}
+
+// TODO(terry): Move this failure case to a failure_test.dart when the analyzer
+// and validator exit then they'll be a bunch more checks.
+void testSelectorFailures() {
+ var errors = [];
+
+ // Test for invalid class name (can't start with number).
+ var selectorAst = selector('.foobar .1a-story .xyzzy', errors: errors);
+ expect(errors.isEmpty, false);
+ expect(errors[0].toString(), r'''
+error :1:9: name must start with a alpha character, but found a number
+.foobar .1a-story .xyzzy
+ ^^''');
+}
+
+main() {
+ test('Valid Selectors', testSelectorSuccesses);
+ test('Invalid Selectors', testSelectorFailures);
+}
« no previous file with comments | « pkg/csslib/test/run_all.dart ('k') | pkg/csslib/test/testing.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698