| OLD | NEW |
| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 | 7 |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import 'test_common.dart'; | 10 import 'test_common.dart'; |
| 11 import 'test_utils.dart'; | 11 import 'test_utils.dart'; |
| 12 | 12 |
| 13 void main() { | 13 void main() { |
| 14 | 14 |
| 15 initUtils(); | 15 initUtils(); |
| 16 | 16 |
| 17 // Core matchers | 17 // Core matchers |
| 18 | 18 |
| 19 group('Core matchers', () { | 19 group('Core matchers', () { |
| 20 | 20 |
| 21 test('isTrue', () { | 21 test('isTrue', () { |
| 22 shouldPass(true, isTrue); | 22 shouldPass(true, isTrue); |
| 23 shouldFail(false, isTrue, "Expected: true But: was <false>. " | 23 shouldFail(false, isTrue, "Expected: true Actual: <false>"); |
| 24 "Actual: <false>"); | |
| 25 }); | 24 }); |
| 26 | 25 |
| 27 test('isFalse', () { | 26 test('isFalse', () { |
| 28 shouldPass(false, isFalse); | 27 shouldPass(false, isFalse); |
| 29 shouldFail(10, isFalse, "Expected: false But: was <10>. " | 28 shouldFail(10, isFalse, "Expected: false Actual: <10>"); |
| 30 "Actual: <10>"); | 29 shouldFail(true, isFalse, "Expected: false Actual: <true>"); |
| 31 shouldFail(true, isFalse, "Expected: false But: was <true>. " | |
| 32 "Actual: <true>"); | |
| 33 }); | 30 }); |
| 34 | 31 |
| 35 test('isNull', () { | 32 test('isNull', () { |
| 36 shouldPass(null, isNull); | 33 shouldPass(null, isNull); |
| 37 shouldFail(false, isNull, "Expected: null But: was <false>. " | 34 shouldFail(false, isNull, "Expected: null Actual: <false>"); |
| 38 "Actual: <false>"); | |
| 39 }); | 35 }); |
| 40 | 36 |
| 41 test('isNotNull', () { | 37 test('isNotNull', () { |
| 42 shouldPass(false, isNotNull); | 38 shouldPass(false, isNotNull); |
| 43 shouldFail(null, isNotNull, "Expected: not null But: was <null>. " | 39 shouldFail(null, isNotNull, "Expected: not null Actual: <null>"); |
| 44 "Actual: <null>"); | |
| 45 }); | 40 }); |
| 46 | 41 |
| 47 test('same', () { | 42 test('same', () { |
| 48 var a = new Map(); | 43 var a = new Map(); |
| 49 var b = new Map(); | 44 var b = new Map(); |
| 50 shouldPass(a, same(a)); | 45 shouldPass(a, same(a)); |
| 51 shouldFail(b, same(a), "Expected: same instance as {} But: was {}. " | 46 shouldFail(b, same(a), "Expected: same instance as {} Actual: {}"); |
| 52 "Actual: {}"); | |
| 53 }); | 47 }); |
| 54 | 48 |
| 55 test('equals', () { | 49 test('equals', () { |
| 56 var a = new Map(); | 50 var a = new Map(); |
| 57 var b = new Map(); | 51 var b = new Map(); |
| 58 shouldPass(a, equals(a)); | 52 shouldPass(a, equals(a)); |
| 59 shouldPass(a, equals(b)); | 53 shouldPass(a, equals(b)); |
| 60 }); | 54 }); |
| 61 | 55 |
| 62 test('anything', () { | 56 test('anything', () { |
| 63 var a = new Map(); | 57 var a = new Map(); |
| 64 shouldPass(0, anything); | 58 shouldPass(0, anything); |
| 65 shouldPass(null, anything); | 59 shouldPass(null, anything); |
| 66 shouldPass(a, anything); | 60 shouldPass(a, anything); |
| 67 shouldFail(a, isNot(anything), "Expected: not anything " | 61 shouldFail(a, isNot(anything), "Expected: not anything Actual: {}"); |
| 68 "But: was {}. Actual: {}"); | |
| 69 }); | 62 }); |
| 70 | 63 |
| 71 test('throws', () { | 64 test('throws', () { |
| 72 shouldFail(doesNotThrow, throws, | 65 shouldFail(doesNotThrow, throws, |
| 73 matches( | 66 matches( |
| 74 r"Expected: throws an exception +But: no exception\." | 67 r"Expected: throws" |
| 75 r"Actual: <Closure(: \(dynamic\) => dynamic " | 68 r" Actual: <Closure(: \(dynamic\) => dynamic " |
| 76 r"from Function 'doesNotThrow': static\.)?>")); | 69 r"from Function 'doesNotThrow': static\.)?>" |
| 70 r" Which: did not throw")); |
| 77 shouldPass(doesThrow, throws); | 71 shouldPass(doesThrow, throws); |
| 78 shouldFail(true, throws, | 72 shouldFail(true, throws, |
| 79 "Expected: throws an exception But: not a Function or Future. " | 73 "Expected: throws" |
| 80 "Actual: <true>"); | 74 " Actual: <true>" |
| 75 " Which: is not a Function or Future"); |
| 81 }); | 76 }); |
| 82 | 77 |
| 83 test('throwsA', () { | 78 test('throwsA', () { |
| 84 shouldPass(doesThrow, throwsA(equals('X'))); | 79 shouldPass(doesThrow, throwsA(equals('X'))); |
| 85 shouldFail(doesThrow, throwsA(equals('Y')), | 80 shouldFail(doesThrow, throwsA(equals('Y')), |
| 86 matches( | 81 matches( |
| 87 r"Expected: throws an exception which matches 'Y' +" | 82 r"Expected: throws 'Y'" |
| 88 r"But: exception 'X' does not match 'Y'\." | 83 r" Actual: <Closure(: \(dynamic\) => dynamic " |
| 89 r"Actual: <Closure(: \(dynamic\) => dynamic " | 84 r"from Function 'doesThrow': static\.)?>" |
| 90 r"from Function 'doesThrow': static\.)?>")); | 85 r" Which: threw 'X'")); |
| 91 }); | 86 }); |
| 92 | 87 |
| 93 test('returnsNormally', () { | 88 test('returnsNormally', () { |
| 94 shouldPass(doesNotThrow, returnsNormally); | 89 shouldPass(doesNotThrow, returnsNormally); |
| 95 shouldFail(doesThrow, returnsNormally, | 90 shouldFail(doesThrow, returnsNormally, |
| 96 matches( | 91 matches( |
| 97 r"Expected: return normally +But: threw 'X'\." | 92 r"Expected: return normally" |
| 98 r"Actual: <Closure(: \(dynamic\) => dynamic " | 93 r" Actual: <Closure(: \(dynamic\) => dynamic " |
| 99 r"from Function 'doesThrow': static\.)?>")); | 94 r"from Function 'doesThrow': static\.)?>" |
| 95 r" Which: threw 'X'")); |
| 100 }); | 96 }); |
| 101 | 97 |
| 98 |
| 102 test('hasLength', () { | 99 test('hasLength', () { |
| 103 var a = new Map(); | 100 var a = new Map(); |
| 104 var b = new List(); | 101 var b = new List(); |
| 105 shouldPass(a, hasLength(0)); | 102 shouldPass(a, hasLength(0)); |
| 106 shouldPass(b, hasLength(0)); | 103 shouldPass(b, hasLength(0)); |
| 107 shouldPass('a', hasLength(1)); | 104 shouldPass('a', hasLength(1)); |
| 108 shouldFail(0, hasLength(0), new PrefixMatcher( | 105 shouldFail(0, hasLength(0), new PrefixMatcher( |
| 109 "Expected: an object with length of <0> " | 106 "Expected: an object with length of <0> " |
| 110 "But: had no length property." | 107 "Actual: <0> " |
| 111 "Actual: <0>")); | 108 "Which: has no length property")); |
| 112 | 109 |
| 113 b.add(0); | 110 b.add(0); |
| 114 shouldPass(b, hasLength(1)); | 111 shouldPass(b, hasLength(1)); |
| 115 shouldFail(b, hasLength(2), | 112 shouldFail(b, hasLength(2), |
| 116 "Expected: an object with length of <2> " | 113 "Expected: an object with length of <2> " |
| 117 "But: had length of <1>. " | 114 "Actual: [0] " |
| 118 "Actual: [0]"); | 115 "Which: has length of <1>"); |
| 119 | 116 |
| 120 b.add(0); | 117 b.add(0); |
| 121 shouldFail(b, hasLength(1), | 118 shouldFail(b, hasLength(1), |
| 122 "Expected: an object with length of <1> " | 119 "Expected: an object with length of <1> " |
| 123 "But: had length of <2>. " | 120 "Actual: [0, 0] " |
| 124 "Actual: [0, 0]"); | 121 "Which: has length of <2>"); |
| 125 shouldPass(b, hasLength(2)); | 122 shouldPass(b, hasLength(2)); |
| 126 }); | 123 }); |
| 127 | 124 |
| 128 test('scalar type mismatch', () { | 125 test('scalar type mismatch', () { |
| 129 shouldFail('error', equals(5.1), | 126 shouldFail('error', equals(5.1), |
| 130 "Expected: <5.1> " | 127 "Expected: <5.1> " |
| 131 "But: was 'error'. Actual: 'error'"); | 128 "Actual: 'error'"); |
| 132 }); | 129 }); |
| 133 | 130 |
| 134 test('nested type mismatch', () { | 131 test('nested type mismatch', () { |
| 135 shouldFail(['error'], equals([5.1]), | 132 shouldFail(['error'], equals([5.1]), |
| 136 "Expected: [5.1] " | 133 "Expected: [5.1] " |
| 137 "But: expected <5.1> but was 'error' mismatch at position 0. " | 134 "Actual: ['error'] " |
| 138 "Actual: ['error']"); | 135 "Which: was 'error' instead of <5.1> at location [0]"); |
| 139 }); | 136 }); |
| 140 | 137 |
| 141 test('doubly-nested type mismatch', () { | 138 test('doubly-nested type mismatch', () { |
| 142 shouldFail([['error']], equals([[5.1]]), | 139 shouldFail([['error']], equals([[5.1]]), |
| 143 "Expected: [[5.1]] " | 140 "Expected: [[5.1]] " |
| 144 "But: expected <5.1> but was 'error' " | 141 "Actual: [['error']] " |
| 145 "mismatch at position 0 mismatch at position 0. " | 142 "Which: was 'error' instead of <5.1> at location [0][0]"); |
| 146 "Actual: [['error']]"); | 143 }); |
| 144 |
| 145 test('doubly nested inequality', () { |
| 146 var actual1 = [['foo', 'bar'], ['foo'], 3, []]; |
| 147 var expected1 = [['foo', 'bar'], ['foo'], 4, []]; |
| 148 var reason1 = "Expected: [['foo', 'bar'], ['foo'], 4, []] " |
| 149 "Actual: [['foo', 'bar'], ['foo'], 3, []] " |
| 150 "Which: was <3> instead of <4> at location [2]"; |
| 151 |
| 152 var actual2 = [['foo', 'barry'], ['foo'], 4, []]; |
| 153 var expected2 = [['foo', 'bar'], ['foo'], 4, []]; |
| 154 var reason2 = "Expected: [['foo', 'bar'], ['foo'], 4, []] " |
| 155 "Actual: [['foo', 'barry'], ['foo'], 4, []] " |
| 156 "Which: was 'barry' instead of 'bar' at location [0][1]"; |
| 157 |
| 158 var actual3 = [['foo', 'bar'], ['foo'], 4, {'foo':'bar'}]; |
| 159 var expected3 = [['foo', 'bar'], ['foo'], 4, {'foo':'barry'}]; |
| 160 var reason3 = "Expected: [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}] " |
| 161 "Actual: [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}] " |
| 162 "Which: was 'bar' instead of 'barry' at location [3]['foo']"; |
| 163 |
| 164 shouldFail(actual1, equals(expected1), reason1); |
| 165 shouldFail(actual2, equals(expected2), reason2); |
| 166 shouldFail(actual3, equals(expected3), reason3); |
| 147 }); | 167 }); |
| 148 }); | 168 }); |
| 149 | 169 |
| 150 group('Numeric Matchers', () { | 170 group('Numeric Matchers', () { |
| 151 | 171 |
| 152 test('greaterThan', () { | 172 test('greaterThan', () { |
| 153 shouldPass(10, greaterThan(9)); | 173 shouldPass(10, greaterThan(9)); |
| 154 shouldFail(9, greaterThan(10), | 174 shouldFail(9, greaterThan(10), |
| 155 "Expected: a value greater than <10> But: was <9>. Actual: <9>"); | 175 "Expected: a value greater than <10> " |
| 176 "Actual: <9> " |
| 177 "Which: is not a value greater than <10>"); |
| 156 }); | 178 }); |
| 157 | 179 |
| 158 test('greaterThanOrEqualTo', () { | 180 test('greaterThanOrEqualTo', () { |
| 159 shouldPass(10, greaterThanOrEqualTo(10)); | 181 shouldPass(10, greaterThanOrEqualTo(10)); |
| 160 shouldFail(9, greaterThanOrEqualTo(10), | 182 shouldFail(9, greaterThanOrEqualTo(10), |
| 161 "Expected: a value greater than or equal to <10> But: was <9>. " | 183 "Expected: a value greater than or equal to <10> " |
| 162 "Actual: <9>"); | 184 "Actual: <9> " |
| 185 "Which: is not a value greater than or equal to <10>"); |
| 163 }); | 186 }); |
| 164 | 187 |
| 165 test('lessThan', () { | 188 test('lessThan', () { |
| 166 shouldFail(10, lessThan(9), "Expected: a value less than <9> " | 189 shouldFail(10, lessThan(9), |
| 167 "But: was <10>. Actual: <10>"); | 190 "Expected: a value less than <9> " |
| 191 "Actual: <10> " |
| 192 "Which: is not a value less than <9>"); |
| 168 shouldPass(9, lessThan(10)); | 193 shouldPass(9, lessThan(10)); |
| 169 }); | 194 }); |
| 170 | 195 |
| 171 test('lessThanOrEqualTo', () { | 196 test('lessThanOrEqualTo', () { |
| 172 shouldPass(10, lessThanOrEqualTo(10)); | 197 shouldPass(10, lessThanOrEqualTo(10)); |
| 173 shouldFail(11, lessThanOrEqualTo(10), | 198 shouldFail(11, lessThanOrEqualTo(10), |
| 174 "Expected: a value less than or equal to <10> But: was <11>. " | 199 "Expected: a value less than or equal to <10> " |
| 175 "Actual: <11>"); | 200 "Actual: <11> " |
| 201 "Which: is not a value less than or equal to <10>"); |
| 176 }); | 202 }); |
| 177 | 203 |
| 178 test('isZero', () { | 204 test('isZero', () { |
| 179 shouldPass(0, isZero); | 205 shouldPass(0, isZero); |
| 180 shouldFail(1, isZero, "Expected: a value equal to <0> But: was <1>." | 206 shouldFail(1, isZero, |
| 181 " Actual: <1>"); | 207 "Expected: a value equal to <0> " |
| 208 "Actual: <1> " |
| 209 "Which: is not a value equal to <0>"); |
| 182 }); | 210 }); |
| 183 | 211 |
| 184 test('isNonZero', () { | 212 test('isNonZero', () { |
| 185 shouldFail(0, isNonZero, "Expected: a value not equal to <0> " | 213 shouldFail(0, isNonZero, |
| 186 "But: was <0>. Actual: <0>"); | 214 "Expected: a value not equal to <0> " |
| 215 "Actual: <0> " |
| 216 "Which: is not a value not equal to <0>"); |
| 187 shouldPass(1, isNonZero); | 217 shouldPass(1, isNonZero); |
| 188 }); | 218 }); |
| 189 | 219 |
| 190 test('isPositive', () { | 220 test('isPositive', () { |
| 191 shouldFail(-1, isPositive, "Expected: a positive value " | 221 shouldFail(-1, isPositive, |
| 192 "But: was <-1>. Actual: <-1>"); | 222 "Expected: a positive value " |
| 193 shouldFail(0, isPositive, "Expected: a positive value " | 223 "Actual: <-1> " |
| 194 "But: was <0>. Actual: <0>"); | 224 "Which: is not a positive value"); |
| 225 shouldFail(0, isPositive, |
| 226 "Expected: a positive value " |
| 227 "Actual: <0> " |
| 228 "Which: is not a positive value"); |
| 195 shouldPass(1, isPositive); | 229 shouldPass(1, isPositive); |
| 196 }); | 230 }); |
| 197 | 231 |
| 198 test('isNegative', () { | 232 test('isNegative', () { |
| 199 shouldPass(-1, isNegative); | 233 shouldPass(-1, isNegative); |
| 200 shouldFail(0, isNegative, | 234 shouldFail(0, isNegative, |
| 201 "Expected: a negative value But: was <0>. Actual: <0>"); | 235 "Expected: a negative value " |
| 236 "Actual: <0> " |
| 237 "Which: is not a negative value"); |
| 202 }); | 238 }); |
| 203 | 239 |
| 204 test('isNonPositive', () { | 240 test('isNonPositive', () { |
| 205 shouldPass(-1, isNonPositive); | 241 shouldPass(-1, isNonPositive); |
| 206 shouldPass(0, isNonPositive); | 242 shouldPass(0, isNonPositive); |
| 207 shouldFail(1, isNonPositive, | 243 shouldFail(1, isNonPositive, |
| 208 "Expected: a non-positive value But: was <1>. Actual: <1>"); | 244 "Expected: a non-positive value " |
| 245 "Actual: <1> " |
| 246 "Which: is not a non-positive value"); |
| 209 }); | 247 }); |
| 210 | 248 |
| 211 test('isNonNegative', () { | 249 test('isNonNegative', () { |
| 212 shouldPass(1, isNonNegative); | 250 shouldPass(1, isNonNegative); |
| 213 shouldPass(0, isNonNegative); | 251 shouldPass(0, isNonNegative); |
| 214 shouldFail(-1, isNonNegative, | 252 shouldFail(-1, isNonNegative, |
| 215 "Expected: a non-negative value But: was <-1>. Actual: <-1>"); | 253 "Expected: a non-negative value " |
| 254 "Actual: <-1> " |
| 255 "Which: is not a non-negative value"); |
| 216 }); | 256 }); |
| 217 | 257 |
| 218 test('closeTo', () { | 258 test('closeTo', () { |
| 219 shouldPass(0, closeTo(0, 1)); | 259 shouldPass(0, closeTo(0, 1)); |
| 220 shouldPass(-1, closeTo(0, 1)); | 260 shouldPass(-1, closeTo(0, 1)); |
| 221 shouldPass(1, closeTo(0, 1)); | 261 shouldPass(1, closeTo(0, 1)); |
| 222 shouldFail(1.001, closeTo(0, 1), | 262 shouldFail(1.001, closeTo(0, 1), |
| 223 "Expected: a numeric value within <1> of <0> " | 263 "Expected: a numeric value within <1> of <0> " |
| 224 "But: differed by <1.001>. " | 264 "Actual: <1.001> " |
| 225 "Actual: <1.001>"); | 265 "Which: differs by <1.001>"); |
| 226 shouldFail(-1.001, closeTo(0, 1), | 266 shouldFail(-1.001, closeTo(0, 1), |
| 227 "Expected: a numeric value within <1> of <0> " | 267 "Expected: a numeric value within <1> of <0> " |
| 228 "But: differed by <1.001>. " | 268 "Actual: <-1.001> " |
| 229 "Actual: <-1.001>"); | 269 "Which: differs by <1.001>"); |
| 230 }); | 270 }); |
| 231 | 271 |
| 232 test('inInclusiveRange', () { | 272 test('inInclusiveRange', () { |
| 233 shouldFail(-1, inInclusiveRange(0,2), | 273 shouldFail(-1, inInclusiveRange(0,2), |
| 234 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 274 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
| 235 "But: was <-1>. Actual: <-1>"); | 275 "Actual: <-1>"); |
| 236 shouldPass(0, inInclusiveRange(0,2)); | 276 shouldPass(0, inInclusiveRange(0,2)); |
| 237 shouldPass(1, inInclusiveRange(0,2)); | 277 shouldPass(1, inInclusiveRange(0,2)); |
| 238 shouldPass(2, inInclusiveRange(0,2)); | 278 shouldPass(2, inInclusiveRange(0,2)); |
| 239 shouldFail(3, inInclusiveRange(0,2), | 279 shouldFail(3, inInclusiveRange(0,2), |
| 240 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 280 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
| 241 "But: was <3>. Actual: <3>"); | 281 "Actual: <3>"); |
| 242 }); | 282 }); |
| 243 | 283 |
| 244 test('inExclusiveRange', () { | 284 test('inExclusiveRange', () { |
| 245 shouldFail(0, inExclusiveRange(0,2), | 285 shouldFail(0, inExclusiveRange(0,2), |
| 246 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 286 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
| 247 "But: was <0>. Actual: <0>"); | 287 "Actual: <0>"); |
| 248 shouldPass(1, inExclusiveRange(0,2)); | 288 shouldPass(1, inExclusiveRange(0,2)); |
| 249 shouldFail(2, inExclusiveRange(0,2), | 289 shouldFail(2, inExclusiveRange(0,2), |
| 250 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 290 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
| 251 "But: was <2>. Actual: <2>"); | 291 "Actual: <2>"); |
| 252 }); | 292 }); |
| 253 | 293 |
| 254 test('inOpenClosedRange', () { | 294 test('inOpenClosedRange', () { |
| 255 shouldFail(0, inOpenClosedRange(0,2), | 295 shouldFail(0, inOpenClosedRange(0,2), |
| 256 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " | 296 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " |
| 257 "But: was <0>. Actual: <0>"); | 297 "Actual: <0>"); |
| 258 shouldPass(1, inOpenClosedRange(0,2)); | 298 shouldPass(1, inOpenClosedRange(0,2)); |
| 259 shouldPass(2, inOpenClosedRange(0,2)); | 299 shouldPass(2, inOpenClosedRange(0,2)); |
| 260 }); | 300 }); |
| 261 | 301 |
| 262 test('inClosedOpenRange', () { | 302 test('inClosedOpenRange', () { |
| 263 shouldPass(0, inClosedOpenRange(0,2)); | 303 shouldPass(0, inClosedOpenRange(0,2)); |
| 264 shouldPass(1, inClosedOpenRange(0,2)); | 304 shouldPass(1, inClosedOpenRange(0,2)); |
| 265 shouldFail(2, inClosedOpenRange(0,2), | 305 shouldFail(2, inClosedOpenRange(0,2), |
| 266 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " | 306 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " |
| 267 "But: was <2>. Actual: <2>"); | 307 "Actual: <2>"); |
| 268 }); | 308 }); |
| 269 }); | 309 }); |
| 270 | 310 |
| 271 group('String Matchers', () { | 311 group('String Matchers', () { |
| 272 | 312 |
| 273 test('isEmpty', () { | 313 test('isEmpty', () { |
| 274 shouldPass('', isEmpty); | 314 shouldPass('', isEmpty); |
| 275 shouldFail(null, isEmpty, | 315 shouldFail(null, isEmpty, |
| 276 "Expected: empty But: was <null>. Actual: <null>"); | 316 "Expected: empty Actual: <null>"); |
| 277 shouldFail(0, isEmpty, | 317 shouldFail(0, isEmpty, |
| 278 "Expected: empty But: was <0>. Actual: <0>"); | 318 "Expected: empty Actual: <0>"); |
| 279 shouldFail('a', isEmpty, "Expected: empty But: was 'a'. Actual: 'a'"); | 319 shouldFail('a', isEmpty, "Expected: empty Actual: 'a'"); |
| 280 }); | 320 }); |
| 281 | 321 |
| 282 test('equalsIgnoringCase', () { | 322 test('equalsIgnoringCase', () { |
| 283 shouldPass('hello', equalsIgnoringCase('HELLO')); | 323 shouldPass('hello', equalsIgnoringCase('HELLO')); |
| 284 shouldFail('hi', equalsIgnoringCase('HELLO'), | 324 shouldFail('hi', equalsIgnoringCase('HELLO'), |
| 285 "Expected: 'HELLO' ignoring case But: was 'hi'. Actual: 'hi'"); | 325 "Expected: 'HELLO' ignoring case Actual: 'hi'"); |
| 286 }); | 326 }); |
| 287 | 327 |
| 288 test('equalsIgnoringWhitespace', () { | 328 test('equalsIgnoringWhitespace', () { |
| 289 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); | 329 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); |
| 290 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), | 330 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), |
| 291 "Expected: 'hello world' ignoring whitespace " | 331 "Expected: 'hello world' ignoring whitespace " |
| 292 "But: was 'helloworld'. Actual: ' helloworld '"); | 332 "Actual: ' helloworld ' " |
| 333 "Which: is 'helloworld' with whitespace compressed"); |
| 293 }); | 334 }); |
| 294 | 335 |
| 295 test('startsWith', () { | 336 test('startsWith', () { |
| 296 shouldPass('hello', startsWith('')); | 337 shouldPass('hello', startsWith('')); |
| 297 shouldPass('hello', startsWith('hell')); | 338 shouldPass('hello', startsWith('hell')); |
| 298 shouldPass('hello', startsWith('hello')); | 339 shouldPass('hello', startsWith('hello')); |
| 299 shouldFail('hello', startsWith('hello '), | 340 shouldFail('hello', startsWith('hello '), |
| 300 "Expected: a string starting with 'hello ' " | 341 "Expected: a string starting with 'hello ' " |
| 301 "But: was 'hello'. Actual: 'hello'"); | 342 "Actual: 'hello'"); |
| 302 }); | 343 }); |
| 303 | 344 |
| 304 test('endsWith', () { | 345 test('endsWith', () { |
| 305 shouldPass('hello', endsWith('')); | 346 shouldPass('hello', endsWith('')); |
| 306 shouldPass('hello', endsWith('lo')); | 347 shouldPass('hello', endsWith('lo')); |
| 307 shouldPass('hello', endsWith('hello')); | 348 shouldPass('hello', endsWith('hello')); |
| 308 shouldFail('hello', endsWith(' hello'), | 349 shouldFail('hello', endsWith(' hello'), |
| 309 "Expected: a string ending with ' hello' " | 350 "Expected: a string ending with ' hello' " |
| 310 "But: was 'hello'. Actual: 'hello'"); | 351 "Actual: 'hello'"); |
| 311 }); | 352 }); |
| 312 | 353 |
| 313 test('contains', () { | 354 test('contains', () { |
| 314 shouldPass('hello', contains('')); | 355 shouldPass('hello', contains('')); |
| 315 shouldPass('hello', contains('h')); | 356 shouldPass('hello', contains('h')); |
| 316 shouldPass('hello', contains('o')); | 357 shouldPass('hello', contains('o')); |
| 317 shouldPass('hello', contains('hell')); | 358 shouldPass('hello', contains('hell')); |
| 318 shouldPass('hello', contains('hello')); | 359 shouldPass('hello', contains('hello')); |
| 319 shouldFail('hello', contains(' '), | 360 shouldFail('hello', contains(' '), |
| 320 "Expected: contains ' ' But: was 'hello'. Actual: 'hello'"); | 361 "Expected: contains ' ' Actual: 'hello'"); |
| 321 }); | 362 }); |
| 322 | 363 |
| 323 test('stringContainsInOrder', () { | 364 test('stringContainsInOrder', () { |
| 324 shouldPass('goodbye cruel world', stringContainsInOrder([''])); | 365 shouldPass('goodbye cruel world', stringContainsInOrder([''])); |
| 325 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | 366 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); |
| 326 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | 367 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); |
| 327 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | 368 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); |
| 328 shouldPass('goodbye cruel world', | 369 shouldPass('goodbye cruel world', |
| 329 stringContainsInOrder(['good', 'bye', 'world'])); | 370 stringContainsInOrder(['good', 'bye', 'world'])); |
| 330 shouldPass('goodbye cruel world', | 371 shouldPass('goodbye cruel world', |
| 331 stringContainsInOrder(['goodbye', 'cruel'])); | 372 stringContainsInOrder(['goodbye', 'cruel'])); |
| 332 shouldPass('goodbye cruel world', | 373 shouldPass('goodbye cruel world', |
| 333 stringContainsInOrder(['cruel', 'world'])); | 374 stringContainsInOrder(['cruel', 'world'])); |
| 334 shouldPass('goodbye cruel world', | 375 shouldPass('goodbye cruel world', |
| 335 stringContainsInOrder(['goodbye', 'cruel', 'world'])); | 376 stringContainsInOrder(['goodbye', 'cruel', 'world'])); |
| 336 shouldFail('goodbye cruel world', | 377 shouldFail('goodbye cruel world', |
| 337 stringContainsInOrder(['goo', 'cruel', 'bye']), | 378 stringContainsInOrder(['goo', 'cruel', 'bye']), |
| 338 "Expected: a string containing 'goo', 'cruel', 'bye' in order " | 379 "Expected: a string containing 'goo', 'cruel', 'bye' in order " |
| 339 "But: was 'goodbye cruel world'. Actual: 'goodbye cruel world'"); | 380 "Actual: 'goodbye cruel world'"); |
| 340 }); | 381 }); |
| 341 | 382 |
| 342 test('matches', () { | 383 test('matches', () { |
| 343 shouldPass('c0d', matches('[a-z][0-9][a-z]')); | 384 shouldPass('c0d', matches('[a-z][0-9][a-z]')); |
| 344 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | 385 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); |
| 345 shouldFail('cOd', matches('[a-z][0-9][a-z]'), | 386 shouldFail('cOd', matches('[a-z][0-9][a-z]'), |
| 346 "Expected: match '[a-z][0-9][a-z]' But: was 'cOd'. Actual: 'cOd'"); | 387 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); |
| 347 }); | 388 }); |
| 348 }); | 389 }); |
| 349 | 390 |
| 350 group('Iterable Matchers', () { | 391 group('Iterable Matchers', () { |
| 351 | 392 |
| 352 test('isEmpty', () { | 393 test('isEmpty', () { |
| 353 shouldPass([], isEmpty); | 394 shouldPass([], isEmpty); |
| 354 shouldFail([1], isEmpty, "Expected: empty But: was [1]. Actual: [1]"); | 395 shouldFail([1], isEmpty, "Expected: empty Actual: [1]"); |
| 355 }); | 396 }); |
| 356 | 397 |
| 357 test('contains', () { | 398 test('contains', () { |
| 358 var d = [1, 2]; | 399 var d = [1, 2]; |
| 359 shouldPass(d, contains(1)); | 400 shouldPass(d, contains(1)); |
| 360 shouldFail(d, contains(0), "Expected: contains <0> " | 401 shouldFail(d, contains(0), "Expected: contains <0> " |
| 361 "But: was [1, 2]. Actual: [1, 2]"); | 402 "Actual: [1, 2]"); |
| 362 }); | 403 }); |
| 363 | 404 |
| 364 test('isIn', () { | 405 test('isIn', () { |
| 365 var d = [1, 2]; | 406 var d = [1, 2]; |
| 366 shouldPass(1, isIn(d)); | 407 shouldPass(1, isIn(d)); |
| 367 shouldFail(0, isIn(d), "Expected: is in [1, 2] But: was <0>. Actual: <0>")
; | 408 shouldFail(0, isIn(d), "Expected: is in [1, 2] Actual: <0>"); |
| 368 }); | 409 }); |
| 369 | 410 |
| 370 test('everyElement', () { | 411 test('everyElement', () { |
| 371 var d = [1, 2]; | 412 var d = [1, 2]; |
| 372 var e = [1, 1, 1]; | 413 var e = [1, 1, 1]; |
| 373 shouldFail(d, everyElement(1), | 414 shouldFail(d, everyElement(1), |
| 374 "Expected: every element <1> But: position 1 was <2>. " | 415 "Expected: every element(<1>) " |
| 375 "Actual: [1, 2]"); | 416 "Actual: [1, 2] " |
| 417 "Which: has value <2> which doesn't match <1> at index 1"); |
| 376 shouldPass(e, everyElement(1)); | 418 shouldPass(e, everyElement(1)); |
| 377 }); | 419 }); |
| 378 | 420 |
| 421 test('nested everyElement', () { |
| 422 var d = [['foo', 'bar'], ['foo'], []]; |
| 423 var e = [['foo', 'bar'], ['foo'], 3, []]; |
| 424 shouldPass(d, everyElement(anyOf(isEmpty, contains('foo')))); |
| 425 shouldFail(d, everyElement(everyElement(equals('foo'))), |
| 426 "Expected: every element(every element('foo')) " |
| 427 "Actual: [['foo', 'bar'], ['foo'], []] " |
| 428 "Which: has value ['foo', 'bar'] which has value 'bar' " |
| 429 "which is different. Expected: foo Actual: bar ^ " |
| 430 "Differ at offset 0 at index 1 at index 0"); |
| 431 shouldFail(d, everyElement(allOf(hasLength(greaterThan(0)), |
| 432 contains('foo'))), |
| 433 "Expected: every element((an object with length of a value " |
| 434 "greater than <0> and contains 'foo')) " |
| 435 "Actual: [['foo', 'bar'], ['foo'], []] " |
| 436 "Which: has value [] which has length of <0> at index 2"); |
| 437 shouldFail(d, everyElement(allOf(contains('foo'), |
| 438 hasLength(greaterThan(0)))), |
| 439 "Expected: every element((contains 'foo' and " |
| 440 "an object with length of a value greater than <0>)) " |
| 441 "Actual: [['foo', 'bar'], ['foo'], []] " |
| 442 "Which: has value [] which doesn't match (contains 'foo' and " |
| 443 "an object with length of a value greater than <0>) at index 2"); |
| 444 shouldFail(e, everyElement(allOf(contains('foo'), |
| 445 hasLength(greaterThan(0)))), |
| 446 "Expected: every element((contains 'foo' and an object with " |
| 447 "length of a value greater than <0>)) " |
| 448 "Actual: [['foo', 'bar'], ['foo'], 3, []] " |
| 449 "Which: has value <3> which is not a string, map or iterable " |
| 450 "at index 2"); |
| 451 }); |
| 452 |
| 379 test('someElement', () { | 453 test('someElement', () { |
| 380 var d = [1, 2]; | 454 var d = [1, 2]; |
| 381 var e = [1, 1, 1]; | 455 var e = [1, 1, 1]; |
| 382 shouldPass(d, someElement(2)); | 456 shouldPass(d, someElement(2)); |
| 383 shouldFail(e, someElement(2), | 457 shouldFail(e, someElement(2), |
| 384 "Expected: some element <2> But: was [1, 1, 1]. Actual: [1, 1, 1]"); | 458 "Expected: some element <2> Actual: [1, 1, 1]"); |
| 385 }); | 459 }); |
| 386 | 460 |
| 387 test('orderedEquals', () { | 461 test('orderedEquals', () { |
| 388 shouldPass([null], orderedEquals([null])); | 462 shouldPass([null], orderedEquals([null])); |
| 389 var d = [1, 2]; | 463 var d = [1, 2]; |
| 390 shouldPass(d, orderedEquals([1, 2])); | 464 shouldPass(d, orderedEquals([1, 2])); |
| 391 shouldFail(d, orderedEquals([2, 1]), | 465 shouldFail(d, orderedEquals([2, 1]), |
| 392 "Expected: equals [2, 1] ordered " | 466 "Expected: equals [2, 1] ordered " |
| 393 "But: expected <2> but was <1> mismatch at position 0. " | 467 "Actual: [1, 2] " |
| 394 "Actual: [1, 2]"); | 468 "Which: was <1> instead of <2> at location [0]"); |
| 395 }); | 469 }); |
| 396 | 470 |
| 397 test('unorderedEquals', () { | 471 test('unorderedEquals', () { |
| 398 var d = [1, 2]; | 472 var d = [1, 2]; |
| 399 shouldPass(d, unorderedEquals([2, 1])); | 473 shouldPass(d, unorderedEquals([2, 1])); |
| 400 shouldFail(d, unorderedEquals([1]), | 474 shouldFail(d, unorderedEquals([1]), |
| 401 "Expected: equals [1] unordered " | 475 "Expected: equals [1] unordered " |
| 402 "But: has too many elements (2 > 1). " | 476 "Actual: [1, 2] " |
| 403 "Actual: [1, 2]"); | 477 "Which: has too many elements (2 > 1)"); |
| 404 shouldFail(d, unorderedEquals([3, 2, 1]), | 478 shouldFail(d, unorderedEquals([3, 2, 1]), |
| 405 "Expected: equals [3, 2, 1] unordered " | 479 "Expected: equals [3, 2, 1] unordered " |
| 406 "But: has too few elements (2 < 3). " | 480 "Actual: [1, 2] " |
| 407 "Actual: [1, 2]"); | 481 "Which: has too few elements (2 < 3)"); |
| 408 shouldFail(d, unorderedEquals([3, 1]), | 482 shouldFail(d, unorderedEquals([3, 1]), |
| 409 "Expected: equals [3, 1] unordered " | 483 "Expected: equals [3, 1] unordered " |
| 410 "But: has no match for element <3> at position 0. " | 484 "Actual: [1, 2] " |
| 411 "Actual: [1, 2]"); | 485 "Which: has no match for element <3> at index 0"); |
| 412 }); | 486 }); |
| 413 | 487 |
| 414 test('pairwise compare', () { | 488 test('pairwise compare', () { |
| 415 var c = [1, 2]; | 489 var c = [1, 2]; |
| 416 var d = [1, 2, 3]; | 490 var d = [1, 2, 3]; |
| 417 var e = [1, 4, 9]; | 491 var e = [1, 4, 9]; |
| 418 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, | 492 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, |
| 419 "less than or equal"), | 493 "less than or equal"), |
| 420 "Expected: pairwise less than or equal [1, 4, 9] " | 494 "Expected: pairwise less than or equal [1, 4, 9] " |
| 421 "But: not an Iterable. " | 495 "Actual: 'x' " |
| 422 "Actual: 'x'"); | 496 "Which: is not an Iterable"); |
| 423 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), | 497 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), |
| 424 "Expected: pairwise less than or equal [1, 4, 9] " | 498 "Expected: pairwise less than or equal [1, 4, 9] " |
| 425 "But: length was 2 instead of 3. " | 499 "Actual: [1, 2] " |
| 426 "Actual: [1, 2]"); | 500 "Which: has length 2 instead of 3"); |
| 427 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); | 501 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); |
| 428 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), | 502 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), |
| 429 "Expected: pairwise less than [1, 4, 9] " | 503 "Expected: pairwise less than [1, 4, 9] " |
| 430 "But: <1> not less than <1> at position 0. " | 504 "Actual: [1, 2, 3] " |
| 431 "Actual: [1, 2, 3]"); | 505 "Which: has <1> which is not less than <1> at index 0"); |
| 432 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); | 506 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); |
| 433 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), | 507 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), |
| 434 "Expected: pairwise double [1, 4, 9] " | 508 "Expected: pairwise double [1, 4, 9] " |
| 435 "But: <1> not double <1> at position 0. " | 509 "Actual: [1, 2, 3] " |
| 436 "Actual: [1, 2, 3]"); | 510 "Which: has <1> which is not double <1> at index 0"); |
| 437 }); | 511 }); |
| 438 }); | 512 }); |
| 439 | 513 |
| 440 group('Map Matchers', () { | 514 group('Map Matchers', () { |
| 441 | 515 |
| 442 test('isEmpty', () { | 516 test('isEmpty', () { |
| 443 var a = new Map(); | 517 var a = new Map(); |
| 444 shouldPass({}, isEmpty); | 518 shouldPass({}, isEmpty); |
| 445 shouldPass(a, isEmpty); | 519 shouldPass(a, isEmpty); |
| 446 a['foo'] = 'bar'; | 520 a['foo'] = 'bar'; |
| 447 shouldFail(a, isEmpty, "Expected: empty But: was {'foo': 'bar'}. " | 521 shouldFail(a, isEmpty, "Expected: empty " |
| 448 "Actual: {'foo': 'bar'}"); | 522 "Actual: {'foo': 'bar'}"); |
| 449 }); | 523 }); |
| 450 | 524 |
| 451 test('equals', () { | 525 test('equals', () { |
| 452 var a = new Map(); | 526 var a = new Map(); |
| 453 a['foo'] = 'bar'; | 527 a['foo'] = 'bar'; |
| 454 var b = new Map(); | 528 var b = new Map(); |
| 455 b['foo'] = 'bar'; | 529 b['foo'] = 'bar'; |
| 456 var c = new Map(); | 530 var c = new Map(); |
| 457 c['bar'] = 'foo'; | 531 c['bar'] = 'foo'; |
| 458 shouldPass(a, equals(b)); | 532 shouldPass(a, equals(b)); |
| 459 shouldFail(b, equals(c), | 533 shouldFail(b, equals(c), |
| 460 "Expected: {'bar': 'foo'} But: missing map key 'bar'. " | 534 "Expected: {'bar': 'foo'} " |
| 461 "Actual: {'foo': 'bar'}"); | 535 "Actual: {'foo': 'bar'} " |
| 536 "Which: is missing map key 'bar'"); |
| 462 }); | 537 }); |
| 463 | 538 |
| 464 test('equals with different lengths', () { | 539 test('equals with different lengths', () { |
| 465 var a = new LinkedHashMap(); | 540 var a = new LinkedHashMap(); |
| 466 a['foo'] = 'bar'; | 541 a['foo'] = 'bar'; |
| 467 var b = new LinkedHashMap(); | 542 var b = new LinkedHashMap(); |
| 468 b['foo'] = 'bar'; | 543 b['foo'] = 'bar'; |
| 469 b['bar'] = 'foo'; | 544 b['bar'] = 'foo'; |
| 470 var c = new LinkedHashMap(); | 545 var c = new LinkedHashMap(); |
| 471 c['bar'] = 'foo'; | 546 c['bar'] = 'foo'; |
| 472 c['barrista'] = 'caffeine'; | 547 c['barrista'] = 'caffeine'; |
| 473 shouldFail(a, equals(b), | 548 shouldFail(a, equals(b), |
| 474 "Expected: {'foo': 'bar', 'bar': 'foo'} " | 549 "Expected: {'foo': 'bar', 'bar': 'foo'} " |
| 475 "But: different map lengths; missing map key 'bar'. " | 550 "Actual: {'foo': 'bar'} " |
| 476 "Actual: {'foo': 'bar'}"); | 551 "Which: has different length and is missing map key 'bar'"); |
| 477 shouldFail(b, equals(a), | 552 shouldFail(b, equals(a), |
| 478 "Expected: {'foo': 'bar'} " | 553 "Expected: {'foo': 'bar'} " |
| 479 "But: different map lengths; extra map key 'bar'. " | 554 "Actual: {'foo': 'bar', 'bar': 'foo'} " |
| 480 "Actual: {'foo': 'bar', 'bar': 'foo'}"); | 555 "Which: has different length and has extra map key 'bar'"); |
| 481 shouldFail(b, equals(c), | 556 shouldFail(b, equals(c), |
| 482 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " | 557 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 483 "But: missing map key 'barrista'. " | 558 "Actual: {'foo': 'bar', 'bar': 'foo'} " |
| 484 "Actual: {'foo': 'bar', 'bar': 'foo'}"); | 559 "Which: is missing map key 'barrista'"); |
| 485 shouldFail(c, equals(b), | 560 shouldFail(c, equals(b), |
| 486 "Expected: {'foo': 'bar', 'bar': 'foo'} " | 561 "Expected: {'foo': 'bar', 'bar': 'foo'} " |
| 487 "But: missing map key 'foo'. " | 562 "Actual: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 488 "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); | 563 "Which: is missing map key 'foo'"); |
| 489 shouldFail(a, equals(c), | 564 shouldFail(a, equals(c), |
| 490 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " | 565 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 491 "But: different map lengths; missing map key 'bar'. " | 566 "Actual: {'foo': 'bar'} " |
| 492 "Actual: {'foo': 'bar'}"); | 567 "Which: has different length and is missing map key 'bar'"); |
| 493 shouldFail(c, equals(a), | 568 shouldFail(c, equals(a), |
| 494 "Expected: {'foo': 'bar'} " | 569 "Expected: {'foo': 'bar'} " |
| 495 "But: different map lengths; missing map key 'foo'. " | 570 "Actual: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 496 "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); | 571 "Which: has different length and is missing map key 'foo'"); |
| 497 }); | 572 }); |
| 498 | 573 |
| 499 test('contains', () { | 574 test('contains', () { |
| 500 var a = new Map(); | 575 var a = new Map(); |
| 501 a['foo'] = 'bar'; | 576 a['foo'] = 'bar'; |
| 502 var b = new Map(); | 577 var b = new Map(); |
| 503 shouldPass(a, contains('foo')); | 578 shouldPass(a, contains('foo')); |
| 504 shouldFail(b, contains('foo'), | 579 shouldFail(b, contains('foo'), |
| 505 "Expected: contains 'foo' But: was {}. Actual: {}"); | 580 "Expected: contains 'foo' Actual: {}"); |
| 506 shouldFail(10, contains('foo'), | 581 shouldFail(10, contains('foo'), |
| 507 "Expected: contains 'foo' But: was <10>. Actual: <10>"); | 582 "Expected: contains 'foo' Actual: <10> " |
| 583 "Which: is not a string, map or iterable"); |
| 508 }); | 584 }); |
| 509 | 585 |
| 510 test('containsValue', () { | 586 test('containsValue', () { |
| 511 var a = new Map(); | 587 var a = new Map(); |
| 512 a['foo'] = 'bar'; | 588 a['foo'] = 'bar'; |
| 513 shouldPass(a, containsValue('bar')); | 589 shouldPass(a, containsValue('bar')); |
| 514 shouldFail(a, containsValue('ba'), | 590 shouldFail(a, containsValue('ba'), |
| 515 "Expected: contains value 'ba' But: was {'foo': 'bar'}. " | 591 "Expected: contains value 'ba' " |
| 516 "Actual: {'foo': 'bar'}"); | 592 "Actual: {'foo': 'bar'}"); |
| 517 }); | 593 }); |
| 518 | 594 |
| 519 test('containsPair', () { | 595 test('containsPair', () { |
| 520 var a = new Map(); | 596 var a = new Map(); |
| 521 a['foo'] = 'bar'; | 597 a['foo'] = 'bar'; |
| 522 shouldPass(a, containsPair('foo', 'bar')); | 598 shouldPass(a, containsPair('foo', 'bar')); |
| 523 shouldFail(a, containsPair('foo', 'ba'), | 599 shouldFail(a, containsPair('foo', 'ba'), |
| 524 "Expected: contains pair 'foo' => 'ba' " | 600 "Expected: contains pair 'foo' => 'ba' " |
| 525 "But: Strings are not equal. Both strings start the same, " | 601 "Actual: {'foo': 'bar'} " |
| 526 "but the given value also has the following trailing characters: r. " | 602 "Which: is different. Both strings start the same, but " |
| 527 "Actual: {'foo': 'bar'}"); | 603 "the given value also has the following trailing characters: r"); |
| 528 shouldFail(a, containsPair('fo', 'bar'), | 604 shouldFail(a, containsPair('fo', 'bar'), |
| 529 "Expected: contains pair 'fo' => 'bar' " | 605 "Expected: contains pair 'fo' => 'bar' " |
| 530 "But: doesn't contain key 'fo'. " | 606 "Actual: {'foo': 'bar'} " |
| 531 "Actual: {'foo': 'bar'}"); | 607 "Which: doesn't contain key 'fo'"); |
| 532 }); | 608 }); |
| 533 | 609 |
| 534 test('hasLength', () { | 610 test('hasLength', () { |
| 535 var a = new Map(); | 611 var a = new Map(); |
| 536 a['foo'] = 'bar'; | 612 a['foo'] = 'bar'; |
| 537 var b = new Map(); | 613 var b = new Map(); |
| 538 shouldPass(a, hasLength(1)); | 614 shouldPass(a, hasLength(1)); |
| 539 shouldFail(b, hasLength(1), | 615 shouldFail(b, hasLength(1), |
| 540 "Expected: an object with length of <1> " | 616 "Expected: an object with length of <1> " |
| 541 "But: had length of <0>. " | 617 "Actual: {} " |
| 542 "Actual: {}"); | 618 "Which: has length of <0>"); |
| 543 }); | 619 }); |
| 544 }); | 620 }); |
| 545 | 621 |
| 546 group('Operator Matchers', () { | 622 group('Operator Matchers', () { |
| 547 | 623 |
| 548 test('anyOf', () { | 624 test('anyOf', () { |
| 549 shouldFail(0, anyOf([equals(1), equals(2)]), | 625 shouldFail(0, anyOf([equals(1), equals(2)]), |
| 550 "Expected: (<1> or <2>) But: was <0>. Actual: <0>"); | 626 "Expected: (<1> or <2>) Actual: <0>"); |
| 551 shouldPass(1, anyOf([equals(1), equals(2)])); | 627 shouldPass(1, anyOf([equals(1), equals(2)])); |
| 552 }); | 628 }); |
| 553 | 629 |
| 554 test('allOf', () { | 630 test('allOf', () { |
| 555 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); | 631 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); |
| 556 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), | 632 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), |
| 557 "Expected: (a value less than <10> and a value greater than <0>) " | 633 "Expected: (a value less than <10> and a value greater than <0>) " |
| 558 "But: was <-1> (wasn't a value greater than <0>). Actual: <-1>"); | 634 "Actual: <-1> " |
| 635 "Which: is not a value greater than <0>"); |
| 559 }); | 636 }); |
| 560 }); | 637 }); |
| 561 | 638 |
| 562 group('Future Matchers', () { | 639 group('Future Matchers', () { |
| 563 | 640 |
| 564 test('completes - unexpected error', () { | 641 test('completes - unexpected error', () { |
| 565 var completer = new Completer(); | 642 var completer = new Completer(); |
| 566 completer.completeError('X'); | 643 completer.completeError('X'); |
| 567 shouldFail(completer.future, completes, | 644 shouldFail(completer.future, completes, |
| 568 contains('Expected future to complete successfully, ' | 645 contains('Expected future to complete successfully, ' |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 test('throwsA - correct error', () { | 685 test('throwsA - correct error', () { |
| 609 var completer = new Completer(); | 686 var completer = new Completer(); |
| 610 completer.completeError('X'); | 687 completer.completeError('X'); |
| 611 shouldPass(completer.future, throwsA(equals('X')), isAsync: true); | 688 shouldPass(completer.future, throwsA(equals('X')), isAsync: true); |
| 612 }); | 689 }); |
| 613 | 690 |
| 614 test('throwsA - wrong error', () { | 691 test('throwsA - wrong error', () { |
| 615 var completer = new Completer(); | 692 var completer = new Completer(); |
| 616 completer.completeError('X'); | 693 completer.completeError('X'); |
| 617 shouldFail(completer.future, throwsA(equals('Y')), | 694 shouldFail(completer.future, throwsA(equals('Y')), |
| 618 "Expected: 'Y' But: Strings are not equal. " | 695 "Expected: 'Y' Actual: 'X' " |
| 619 "Expected: Y Actual: X ^ Differ at position 0. Actual: 'X'", | 696 "Which: is different. " |
| 697 "Expected: Y Actual: X ^ Differ at offset 0", |
| 620 isAsync: true); | 698 isAsync: true); |
| 621 }); | 699 }); |
| 622 }); | 700 }); |
| 623 | 701 |
| 624 group('Predicate Matchers', () { | 702 group('Predicate Matchers', () { |
| 625 test('isInstanceOf', () { | 703 test('isInstanceOf', () { |
| 626 shouldFail(0, predicate((x) => x is String, "an instance of String"), | 704 shouldFail(0, predicate((x) => x is String, "an instance of String"), |
| 627 "Expected: an instance of String But: was <0>. Actual: <0>"); | 705 "Expected: an instance of String Actual: <0>"); |
| 628 shouldPass('cow', predicate((x) => x is String, "an instance of String")); | 706 shouldPass('cow', predicate((x) => x is String, "an instance of String")); |
| 629 }); | 707 }); |
| 630 }); | 708 }); |
| 631 } | 709 } |
| 632 | 710 |
| OLD | NEW |