Re-add minified/unminified tests.
These were mistakenly moved to unittest along with some throws*
matcher tests, but they test matchers in the matcher package.
R=kevmoo@google.com
Review URL: https://codereview.chromium.org//935923002
diff --git a/.status b/.status
index e659275..63937ba 100644
--- a/.status
+++ b/.status
@@ -18,10 +18,10 @@
# The unminified matcher tests test that the real names of Dart types are
# printed. Minified versions of these tests exist that test the behavior when
# minified.
-*_unminified_test: Skip # DO NOT COPY THIS UNLESS YOU WORK ON DART2JS
+build/test/unminified_test: Skip # DO NOT COPY THIS UNLESS YOU WORK ON DART2JS
[ $minified == false ]
# The minified matcher tests test that the minified names of Dart types are
# printed. Unminified versions of these tests exist that test the behavior when
# not minified.
-build/test/*_minified_test: Skip # DO NOT COPY THIS UNLESS YOU WORK ON DART2JS
+build/test/minified_test: Skip # DO NOT COPY THIS UNLESS YOU WORK ON DART2JS
diff --git a/test/minified_test.dart b/test/minified_test.dart
new file mode 100644
index 0000000..34c5cf0
--- /dev/null
+++ b/test/minified_test.dart
@@ -0,0 +1,58 @@
+// Copyright (c) 2015, 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.
+
+// This file is for matcher tests that rely on the names of various Dart types.
+// These tests will fail when run in minified dart2js, since the names will be
+// mangled. A version of this file that works in minified dart2js is in
+// matchers_minified_test.dart.
+
+import 'package:matcher/matcher.dart';
+import 'package:unittest/unittest.dart';
+
+import 'test_utils.dart';
+
+// A regexp fragment matching a minified name.
+const _MINIFIED_NAME = r"[A-Za-z0-9]{1,3}";
+
+void main() {
+ group('Iterable Matchers', () {
+ test('isEmpty', () {
+ var d = new SimpleIterable(0);
+ var e = new SimpleIterable(1);
+ shouldPass(d, isEmpty);
+ shouldFail(e, isEmpty,
+ matches(r"Expected: empty +Actual: " + _MINIFIED_NAME + r":\[1\]"));
+ });
+
+ test('isNotEmpty', () {
+ var d = new SimpleIterable(0);
+ var e = new SimpleIterable(1);
+ shouldPass(e, isNotEmpty);
+ shouldFail(d, isNotEmpty, matches(
+ r"Expected: non-empty +Actual: " + _MINIFIED_NAME + r":\[\]"));
+ });
+
+ test('contains', () {
+ var d = new SimpleIterable(3);
+ shouldPass(d, contains(2));
+ shouldFail(d, contains(5), matches(r"Expected: contains <5> +"
+ r"Actual: " + _MINIFIED_NAME + r":\[3, 2, 1\]"));
+ });
+ });
+
+ group('Feature Matchers', () {
+ test("Feature Matcher", () {
+ var w = new Widget();
+ w.price = 10;
+ shouldPass(w, new HasPrice(10));
+ shouldPass(w, new HasPrice(greaterThan(0)));
+ shouldFail(w, new HasPrice(greaterThan(10)), matches(
+ r"Expected: Widget with a price that is a value greater than "
+ r"<10> +"
+ r"Actual: <Instance of '" + _MINIFIED_NAME + r"'> +"
+ r"Which: has price with value <10> which is not "
+ r"a value greater than <10>"));
+ });
+ });
+}
diff --git a/test/test_utils.dart b/test/test_utils.dart
index fb342a4..b1a9756 100644
--- a/test/test_utils.dart
+++ b/test/test_utils.dart
@@ -4,6 +4,8 @@
library matcher.test_utils;
+import 'dart:collection';
+
import 'package:unittest/unittest.dart';
void shouldFail(value, Matcher matcher, expected) {
@@ -33,3 +35,52 @@
doesThrow() {
throw 'X';
}
+
+class Widget {
+ int price;
+}
+
+class HasPrice extends CustomMatcher {
+ HasPrice(matcher) : super("Widget with a price that is", "price", matcher);
+ featureValueOf(actual) => actual.price;
+}
+
+class SimpleIterable extends IterableBase<int> {
+ final int count;
+
+ SimpleIterable(this.count);
+
+ bool contains(int val) => count < val ? false : true;
+
+ bool any(bool f(element)) {
+ for (var i = 0; i <= count; i++) {
+ if (f(i)) return true;
+ }
+ return false;
+ }
+
+ String toString() => "<[$count]>";
+
+ Iterator get iterator {
+ return new _SimpleIterator(count);
+ }
+}
+
+class _SimpleIterator implements Iterator<int> {
+ int _count;
+ int _current;
+
+ _SimpleIterator(this._count);
+
+ bool moveNext() {
+ if (_count > 0) {
+ _current = _count;
+ _count--;
+ return true;
+ }
+ _current = null;
+ return false;
+ }
+
+ int get current => _current;
+}
diff --git a/test/unminified_test.dart b/test/unminified_test.dart
new file mode 100644
index 0000000..615c7e8
--- /dev/null
+++ b/test/unminified_test.dart
@@ -0,0 +1,54 @@
+// Copyright (c) 2015, 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.
+
+// This file is for matcher tests that rely on the names of various Dart types.
+// These tests will fail when run in minified dart2js, since the names will be
+// mangled. A version of this file that works in minified dart2js is in
+// matchers_minified_test.dart.
+
+import 'package:matcher/matcher.dart';
+import 'package:unittest/unittest.dart';
+
+import 'test_utils.dart';
+
+void main() {
+ group('Iterable Matchers', () {
+ test('isEmpty', () {
+ var d = new SimpleIterable(0);
+ var e = new SimpleIterable(1);
+ shouldPass(d, isEmpty);
+ shouldFail(e, isEmpty, "Expected: empty "
+ "Actual: SimpleIterable:[1]");
+ });
+
+ test('isNotEmpty', () {
+ var d = new SimpleIterable(0);
+ var e = new SimpleIterable(1);
+ shouldPass(e, isNotEmpty);
+ shouldFail(d, isNotEmpty, "Expected: non-empty "
+ "Actual: SimpleIterable:[]");
+ });
+
+ test('contains', () {
+ var d = new SimpleIterable(3);
+ shouldPass(d, contains(2));
+ shouldFail(d, contains(5), "Expected: contains <5> "
+ "Actual: SimpleIterable:[3, 2, 1]");
+ });
+ });
+
+ group('Feature Matchers', () {
+ test("Feature Matcher", () {
+ var w = new Widget();
+ w.price = 10;
+ shouldPass(w, new HasPrice(10));
+ shouldPass(w, new HasPrice(greaterThan(0)));
+ shouldFail(w, new HasPrice(greaterThan(10)),
+ "Expected: Widget with a price that is a value greater than <10> "
+ "Actual: <Instance of 'Widget'> "
+ "Which: has price with value <10> which is not "
+ "a value greater than <10>");
+ });
+ });
+}