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

Unified Diff: test/core_matchers_test.dart

Issue 1135653004: pkg/(unit)test: include a copy of old matcher (Closed) Base URL: https://github.com/dart-lang/test.git@stable
Patch Set: another nit Created 5 years, 7 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 | « pubspec.yaml ('k') | test/escape_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/core_matchers_test.dart
diff --git a/test/core_matchers_test.dart b/test/core_matchers_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3e16882adc4b8be2c9b5200daf9557c397eb9691
--- /dev/null
+++ b/test/core_matchers_test.dart
@@ -0,0 +1,191 @@
+// 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 unittest.matcher.core_matchers_test;
+
+import 'package:unittest/unittest.dart';
+
+import 'test_utils.dart';
+
+void main() {
+ initUtils();
+
+ test('isTrue', () {
+ shouldPass(true, isTrue);
+ shouldFail(false, isTrue, "Expected: true Actual: <false>");
+ });
+
+ test('isFalse', () {
+ shouldPass(false, isFalse);
+ shouldFail(10, isFalse, "Expected: false Actual: <10>");
+ shouldFail(true, isFalse, "Expected: false Actual: <true>");
+ });
+
+ test('isNull', () {
+ shouldPass(null, isNull);
+ shouldFail(false, isNull, "Expected: null Actual: <false>");
+ });
+
+ test('isNotNull', () {
+ shouldPass(false, isNotNull);
+ shouldFail(null, isNotNull, "Expected: not null Actual: <null>");
+ });
+
+ test('isNaN', () {
+ shouldPass(double.NAN, isNaN);
+ shouldFail(3.1, isNaN, "Expected: NaN Actual: <3.1>");
+ });
+
+ test('isNotNaN', () {
+ shouldPass(3.1, isNotNaN);
+ shouldFail(double.NAN, isNotNaN, "Expected: not NaN Actual: <NaN>");
+ });
+
+ test('same', () {
+ var a = new Map();
+ var b = new Map();
+ shouldPass(a, same(a));
+ shouldFail(b, same(a), "Expected: same instance as {} Actual: {}");
+ });
+
+ test('equals', () {
+ var a = new Map();
+ var b = new Map();
+ shouldPass(a, equals(a));
+ shouldPass(a, equals(b));
+ });
+
+ test('equals with a set', () {
+ var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
+ var set1 = numbers.toSet();
+ numbers.shuffle();
+ var set2 = numbers.toSet();
+
+ shouldPass(set2, equals(set1));
+ shouldPass(numbers, equals(set1));
+ shouldFail([
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8,
+ 9
+ ], equals(set1), matches(r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]"
+ r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9\]"
+ r" Which: does not contain 10"));
+ shouldFail([
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8,
+ 9,
+ 10,
+ 11
+ ], equals(set1), matches(r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]"
+ r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\]"
+ r" Which: larger than expected"));
+ });
+
+ test('anything', () {
+ var a = new Map();
+ shouldPass(0, anything);
+ shouldPass(null, anything);
+ shouldPass(a, anything);
+ shouldFail(a, isNot(anything), "Expected: not anything Actual: {}");
+ });
+
+ test('returnsNormally', () {
+ shouldPass(doesNotThrow, returnsNormally);
+ shouldFail(doesThrow, returnsNormally, matches(r"Expected: return normally"
+ r" Actual: <Closure(: \(\) => dynamic "
+ r"from Function 'doesThrow': static\.)?>"
+ r" Which: threw 'X'"));
+ });
+
+ test('hasLength', () {
+ var a = new Map();
+ var b = new List();
+ shouldPass(a, hasLength(0));
+ shouldPass(b, hasLength(0));
+ shouldPass('a', hasLength(1));
+ shouldFail(0, hasLength(0), new PrefixMatcher(
+ "Expected: an object with length of <0> "
+ "Actual: <0> "
+ "Which: has no length property"));
+
+ b.add(0);
+ shouldPass(b, hasLength(1));
+ shouldFail(b, hasLength(2), "Expected: an object with length of <2> "
+ "Actual: [0] "
+ "Which: has length of <1>");
+
+ b.add(0);
+ shouldFail(b, hasLength(1), "Expected: an object with length of <1> "
+ "Actual: [0, 0] "
+ "Which: has length of <2>");
+ shouldPass(b, hasLength(2));
+ });
+
+ test('scalar type mismatch', () {
+ shouldFail('error', equals(5.1), "Expected: <5.1> "
+ "Actual: 'error'");
+ });
+
+ test('nested type mismatch', () {
+ shouldFail(['error'], equals([5.1]), "Expected: [5.1] "
+ "Actual: ['error'] "
+ "Which: was 'error' instead of <5.1> at location [0]");
+ });
+
+ test('doubly-nested type mismatch', () {
+ shouldFail([['error']], equals([[5.1]]), "Expected: [[5.1]] "
+ "Actual: [['error']] "
+ "Which: was 'error' instead of <5.1> at location [0][0]");
+ });
+
+ test('doubly nested inequality', () {
+ var actual1 = [['foo', 'bar'], ['foo'], 3, []];
+ var expected1 = [['foo', 'bar'], ['foo'], 4, []];
+ var reason1 = "Expected: [['foo', 'bar'], ['foo'], 4, []] "
+ "Actual: [['foo', 'bar'], ['foo'], 3, []] "
+ "Which: was <3> instead of <4> at location [2]";
+
+ var actual2 = [['foo', 'barry'], ['foo'], 4, []];
+ var expected2 = [['foo', 'bar'], ['foo'], 4, []];
+ var reason2 = "Expected: [['foo', 'bar'], ['foo'], 4, []] "
+ "Actual: [['foo', 'barry'], ['foo'], 4, []] "
+ "Which: was 'barry' instead of 'bar' at location [0][1]";
+
+ var actual3 = [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}];
+ var expected3 = [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}];
+ var reason3 = "Expected: [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}] "
+ "Actual: [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}] "
+ "Which: was 'bar' instead of 'barry' at location [3]['foo']";
+
+ shouldFail(actual1, equals(expected1), reason1);
+ shouldFail(actual2, equals(expected2), reason2);
+ shouldFail(actual3, equals(expected3), reason3);
+ });
+
+ test('isInstanceOf', () {
+ shouldFail(0, new isInstanceOf<String>(),
+ "Expected: an instance of String Actual: <0>");
+ shouldPass('cow', new isInstanceOf<String>());
+ });
+
+ group('Predicate Matchers', () {
+ test('isInstanceOf', () {
+ shouldFail(0, predicate((x) => x is String, "an instance of String"),
+ "Expected: an instance of String Actual: <0>");
+ shouldPass('cow', predicate((x) => x is String, "an instance of String"));
+ });
+ });
+}
« no previous file with comments | « pubspec.yaml ('k') | test/escape_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698