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

Side by Side Diff: test/core_matchers_test.dart

Issue 840133003: matcher: fixed status file, formatting, tweaks to readme (Closed) Base URL: https://github.com/dart-lang/matcher.git@master
Patch Set: nits Created 5 years, 11 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') | test/future_matchers_test.dart » ('j') | 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 matcher.core_matchers_test; 5 library matcher.core_matchers_test;
6 6
7 import 'package:matcher/matcher.dart'; 7 import 'package:matcher/matcher.dart';
8 import 'package:unittest/unittest.dart' show test, group; 8 import 'package:unittest/unittest.dart' show test, group;
9 9
10 import 'test_utils.dart'; 10 import 'test_utils.dart';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 }); 58 });
59 59
60 test('equals with a set', () { 60 test('equals with a set', () {
61 var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; 61 var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
62 var set1 = numbers.toSet(); 62 var set1 = numbers.toSet();
63 numbers.shuffle(); 63 numbers.shuffle();
64 var set2 = numbers.toSet(); 64 var set2 = numbers.toSet();
65 65
66 shouldPass(set2, equals(set1)); 66 shouldPass(set2, equals(set1));
67 shouldPass(numbers, equals(set1)); 67 shouldPass(numbers, equals(set1));
68 shouldFail([1, 2, 3, 4, 5, 6, 7, 8, 9], equals(set1), matches( 68 shouldFail([
69 r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]" 69 1,
70 2,
71 3,
72 4,
73 5,
74 6,
75 7,
76 8,
77 9
78 ], equals(set1), matches(r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]"
70 r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9\]" 79 r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9\]"
71 r" Which: does not contain 10")); 80 r" Which: does not contain 10"));
72 shouldFail([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], equals(set1), matches( 81 shouldFail([
73 r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]" 82 1,
83 2,
84 3,
85 4,
86 5,
87 6,
88 7,
89 8,
90 9,
91 10,
92 11
93 ], equals(set1), matches(r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]"
74 r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\]" 94 r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\]"
75 r" Which: larger than expected")); 95 r" Which: larger than expected"));
76 }); 96 });
77 97
78 test('anything', () { 98 test('anything', () {
79 var a = new Map(); 99 var a = new Map();
80 shouldPass(0, anything); 100 shouldPass(0, anything);
81 shouldPass(null, anything); 101 shouldPass(null, anything);
82 shouldPass(a, anything); 102 shouldPass(a, anything);
83 shouldFail(a, isNot(anything), "Expected: not anything Actual: {}"); 103 shouldFail(a, isNot(anything), "Expected: not anything Actual: {}");
84 }); 104 });
85 105
86 test('returnsNormally', () { 106 test('returnsNormally', () {
87 shouldPass(doesNotThrow, returnsNormally); 107 shouldPass(doesNotThrow, returnsNormally);
88 shouldFail(doesThrow, returnsNormally, 108 shouldFail(doesThrow, returnsNormally, matches(r"Expected: return normally"
89 matches( 109 r" Actual: <Closure(: \(\) => dynamic "
90 r"Expected: return normally" 110 r"from Function 'doesThrow': static\.)?>"
91 r" Actual: <Closure(: \(\) => dynamic " 111 r" Which: threw 'X'"));
92 r"from Function 'doesThrow': static\.)?>"
93 r" Which: threw 'X'"));
94 }); 112 });
95 113
96 test('hasLength', () { 114 test('hasLength', () {
97 var a = new Map(); 115 var a = new Map();
98 var b = new List(); 116 var b = new List();
99 shouldPass(a, hasLength(0)); 117 shouldPass(a, hasLength(0));
100 shouldPass(b, hasLength(0)); 118 shouldPass(b, hasLength(0));
101 shouldPass('a', hasLength(1)); 119 shouldPass('a', hasLength(1));
102 shouldFail(0, hasLength(0), new PrefixMatcher( 120 shouldFail(0, hasLength(0), new PrefixMatcher(
103 "Expected: an object with length of <0> " 121 "Expected: an object with length of <0> "
104 "Actual: <0> " 122 "Actual: <0> "
105 "Which: has no length property")); 123 "Which: has no length property"));
106 124
107 b.add(0); 125 b.add(0);
108 shouldPass(b, hasLength(1)); 126 shouldPass(b, hasLength(1));
109 shouldFail(b, hasLength(2), 127 shouldFail(b, hasLength(2), "Expected: an object with length of <2> "
110 "Expected: an object with length of <2> "
111 "Actual: [0] " 128 "Actual: [0] "
112 "Which: has length of <1>"); 129 "Which: has length of <1>");
113 130
114 b.add(0); 131 b.add(0);
115 shouldFail(b, hasLength(1), 132 shouldFail(b, hasLength(1), "Expected: an object with length of <1> "
116 "Expected: an object with length of <1> "
117 "Actual: [0, 0] " 133 "Actual: [0, 0] "
118 "Which: has length of <2>"); 134 "Which: has length of <2>");
119 shouldPass(b, hasLength(2)); 135 shouldPass(b, hasLength(2));
120 }); 136 });
121 137
122 test('scalar type mismatch', () { 138 test('scalar type mismatch', () {
123 shouldFail('error', equals(5.1), 139 shouldFail('error', equals(5.1), "Expected: <5.1> "
124 "Expected: <5.1> "
125 "Actual: 'error'"); 140 "Actual: 'error'");
126 }); 141 });
127 142
128 test('nested type mismatch', () { 143 test('nested type mismatch', () {
129 shouldFail(['error'], equals([5.1]), 144 shouldFail(['error'], equals([5.1]), "Expected: [5.1] "
130 "Expected: [5.1] "
131 "Actual: ['error'] " 145 "Actual: ['error'] "
132 "Which: was 'error' instead of <5.1> at location [0]"); 146 "Which: was 'error' instead of <5.1> at location [0]");
133 }); 147 });
134 148
135 test('doubly-nested type mismatch', () { 149 test('doubly-nested type mismatch', () {
136 shouldFail([['error']], equals([[5.1]]), 150 shouldFail([['error']], equals([[5.1]]), "Expected: [[5.1]] "
137 "Expected: [[5.1]] "
138 "Actual: [['error']] " 151 "Actual: [['error']] "
139 "Which: was 'error' instead of <5.1> at location [0][0]"); 152 "Which: was 'error' instead of <5.1> at location [0][0]");
140 }); 153 });
141 154
142 test('doubly nested inequality', () { 155 test('doubly nested inequality', () {
143 var actual1 = [['foo', 'bar'], ['foo'], 3, []]; 156 var actual1 = [['foo', 'bar'], ['foo'], 3, []];
144 var expected1 = [['foo', 'bar'], ['foo'], 4, []]; 157 var expected1 = [['foo', 'bar'], ['foo'], 4, []];
145 var reason1 = "Expected: [['foo', 'bar'], ['foo'], 4, []] " 158 var reason1 = "Expected: [['foo', 'bar'], ['foo'], 4, []] "
146 "Actual: [['foo', 'bar'], ['foo'], 3, []] " 159 "Actual: [['foo', 'bar'], ['foo'], 3, []] "
147 "Which: was <3> instead of <4> at location [2]"; 160 "Which: was <3> instead of <4> at location [2]";
148 161
149 var actual2 = [['foo', 'barry'], ['foo'], 4, []]; 162 var actual2 = [['foo', 'barry'], ['foo'], 4, []];
150 var expected2 = [['foo', 'bar'], ['foo'], 4, []]; 163 var expected2 = [['foo', 'bar'], ['foo'], 4, []];
151 var reason2 = "Expected: [['foo', 'bar'], ['foo'], 4, []] " 164 var reason2 = "Expected: [['foo', 'bar'], ['foo'], 4, []] "
152 "Actual: [['foo', 'barry'], ['foo'], 4, []] " 165 "Actual: [['foo', 'barry'], ['foo'], 4, []] "
153 "Which: was 'barry' instead of 'bar' at location [0][1]"; 166 "Which: was 'barry' instead of 'bar' at location [0][1]";
154 167
155 var actual3 = [['foo', 'bar'], ['foo'], 4, {'foo':'bar'}]; 168 var actual3 = [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}];
156 var expected3 = [['foo', 'bar'], ['foo'], 4, {'foo':'barry'}]; 169 var expected3 = [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}];
157 var reason3 = "Expected: [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}] " 170 var reason3 = "Expected: [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}] "
158 "Actual: [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}] " 171 "Actual: [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}] "
159 "Which: was 'bar' instead of 'barry' at location [3]['foo']"; 172 "Which: was 'bar' instead of 'barry' at location [3]['foo']";
160 173
161 shouldFail(actual1, equals(expected1), reason1); 174 shouldFail(actual1, equals(expected1), reason1);
162 shouldFail(actual2, equals(expected2), reason2); 175 shouldFail(actual2, equals(expected2), reason2);
163 shouldFail(actual3, equals(expected3), reason3); 176 shouldFail(actual3, equals(expected3), reason3);
164 }); 177 });
165 178
166 test('isInstanceOf', () { 179 test('isInstanceOf', () {
167 shouldFail(0, new isInstanceOf<String>('String'), 180 shouldFail(0, new isInstanceOf<String>('String'),
168 "Expected: an instance of String Actual: <0>"); 181 "Expected: an instance of String Actual: <0>");
169 shouldPass('cow', new isInstanceOf<String>('String')); 182 shouldPass('cow', new isInstanceOf<String>('String'));
170 }); 183 });
171 184
172 group('Predicate Matchers', () { 185 group('Predicate Matchers', () {
173 test('isInstanceOf', () { 186 test('isInstanceOf', () {
174 shouldFail(0, predicate((x) => x is String, "an instance of String"), 187 shouldFail(0, predicate((x) => x is String, "an instance of String"),
175 "Expected: an instance of String Actual: <0>"); 188 "Expected: an instance of String Actual: <0>");
176 shouldPass('cow', predicate((x) => x is String, "an instance of String")); 189 shouldPass('cow', predicate((x) => x is String, "an instance of String"));
177 }); 190 });
178 }); 191 });
179 } 192 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | test/future_matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698