| 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: has mismatch at position 0: expected <5.1> but is 'error'"); |
| 139 }); | 136 }); |
| 140 | 137 |
| 138 // TODO(gram): we used to compound mismatch positions in nested arrays; |
| 139 // try get that to work again. |
| 141 test('doubly-nested type mismatch', () { | 140 test('doubly-nested type mismatch', () { |
| 142 shouldFail([['error']], equals([[5.1]]), | 141 shouldFail([['error']], equals([[5.1]]), |
| 143 "Expected: [[5.1]] " | 142 "Expected: [[5.1]] " |
| 144 "But: expected <5.1> but was 'error' " | 143 "Actual: [['error']] " |
| 145 "mismatch at position 0 mismatch at position 0. " | 144 "Which: has mismatch at position 0: " |
| 146 "Actual: [['error']]"); | 145 "expected <5.1> but is 'error'"); |
| 147 }); | 146 }); |
| 148 }); | 147 }); |
| 149 | 148 |
| 150 group('Numeric Matchers', () { | 149 group('Numeric Matchers', () { |
| 151 | 150 |
| 152 test('greaterThan', () { | 151 test('greaterThan', () { |
| 153 shouldPass(10, greaterThan(9)); | 152 shouldPass(10, greaterThan(9)); |
| 154 shouldFail(9, greaterThan(10), | 153 shouldFail(9, greaterThan(10), |
| 155 "Expected: a value greater than <10> But: was <9>. Actual: <9>"); | 154 "Expected: a value greater than <10> " |
| 155 "Actual: <9> " |
| 156 "Which: is not a value greater than <10>"); |
| 156 }); | 157 }); |
| 157 | 158 |
| 158 test('greaterThanOrEqualTo', () { | 159 test('greaterThanOrEqualTo', () { |
| 159 shouldPass(10, greaterThanOrEqualTo(10)); | 160 shouldPass(10, greaterThanOrEqualTo(10)); |
| 160 shouldFail(9, greaterThanOrEqualTo(10), | 161 shouldFail(9, greaterThanOrEqualTo(10), |
| 161 "Expected: a value greater than or equal to <10> But: was <9>. " | 162 "Expected: a value greater than or equal to <10> " |
| 162 "Actual: <9>"); | 163 "Actual: <9> " |
| 164 "Which: is not a value greater than or equal to <10>"); |
| 163 }); | 165 }); |
| 164 | 166 |
| 165 test('lessThan', () { | 167 test('lessThan', () { |
| 166 shouldFail(10, lessThan(9), "Expected: a value less than <9> " | 168 shouldFail(10, lessThan(9), |
| 167 "But: was <10>. Actual: <10>"); | 169 "Expected: a value less than <9> " |
| 170 "Actual: <10> " |
| 171 "Which: is not a value less than <9>"); |
| 168 shouldPass(9, lessThan(10)); | 172 shouldPass(9, lessThan(10)); |
| 169 }); | 173 }); |
| 170 | 174 |
| 171 test('lessThanOrEqualTo', () { | 175 test('lessThanOrEqualTo', () { |
| 172 shouldPass(10, lessThanOrEqualTo(10)); | 176 shouldPass(10, lessThanOrEqualTo(10)); |
| 173 shouldFail(11, lessThanOrEqualTo(10), | 177 shouldFail(11, lessThanOrEqualTo(10), |
| 174 "Expected: a value less than or equal to <10> But: was <11>. " | 178 "Expected: a value less than or equal to <10> " |
| 175 "Actual: <11>"); | 179 "Actual: <11> " |
| 180 "Which: is not a value less than or equal to <10>"); |
| 176 }); | 181 }); |
| 177 | 182 |
| 178 test('isZero', () { | 183 test('isZero', () { |
| 179 shouldPass(0, isZero); | 184 shouldPass(0, isZero); |
| 180 shouldFail(1, isZero, "Expected: a value equal to <0> But: was <1>." | 185 shouldFail(1, isZero, |
| 181 " Actual: <1>"); | 186 "Expected: a value equal to <0> " |
| 187 "Actual: <1> " |
| 188 "Which: is not a value equal to <0>"); |
| 182 }); | 189 }); |
| 183 | 190 |
| 184 test('isNonZero', () { | 191 test('isNonZero', () { |
| 185 shouldFail(0, isNonZero, "Expected: a value not equal to <0> " | 192 shouldFail(0, isNonZero, |
| 186 "But: was <0>. Actual: <0>"); | 193 "Expected: a value not equal to <0> " |
| 194 "Actual: <0> " |
| 195 "Which: is not a value not equal to <0>"); |
| 187 shouldPass(1, isNonZero); | 196 shouldPass(1, isNonZero); |
| 188 }); | 197 }); |
| 189 | 198 |
| 190 test('isPositive', () { | 199 test('isPositive', () { |
| 191 shouldFail(-1, isPositive, "Expected: a positive value " | 200 shouldFail(-1, isPositive, |
| 192 "But: was <-1>. Actual: <-1>"); | 201 "Expected: a positive value " |
| 193 shouldFail(0, isPositive, "Expected: a positive value " | 202 "Actual: <-1> " |
| 194 "But: was <0>. Actual: <0>"); | 203 "Which: is not a positive value"); |
| 204 shouldFail(0, isPositive, |
| 205 "Expected: a positive value " |
| 206 "Actual: <0> " |
| 207 "Which: is not a positive value"); |
| 195 shouldPass(1, isPositive); | 208 shouldPass(1, isPositive); |
| 196 }); | 209 }); |
| 197 | 210 |
| 198 test('isNegative', () { | 211 test('isNegative', () { |
| 199 shouldPass(-1, isNegative); | 212 shouldPass(-1, isNegative); |
| 200 shouldFail(0, isNegative, | 213 shouldFail(0, isNegative, |
| 201 "Expected: a negative value But: was <0>. Actual: <0>"); | 214 "Expected: a negative value " |
| 215 "Actual: <0> " |
| 216 "Which: is not a negative value"); |
| 202 }); | 217 }); |
| 203 | 218 |
| 204 test('isNonPositive', () { | 219 test('isNonPositive', () { |
| 205 shouldPass(-1, isNonPositive); | 220 shouldPass(-1, isNonPositive); |
| 206 shouldPass(0, isNonPositive); | 221 shouldPass(0, isNonPositive); |
| 207 shouldFail(1, isNonPositive, | 222 shouldFail(1, isNonPositive, |
| 208 "Expected: a non-positive value But: was <1>. Actual: <1>"); | 223 "Expected: a non-positive value " |
| 224 "Actual: <1> " |
| 225 "Which: is not a non-positive value"); |
| 209 }); | 226 }); |
| 210 | 227 |
| 211 test('isNonNegative', () { | 228 test('isNonNegative', () { |
| 212 shouldPass(1, isNonNegative); | 229 shouldPass(1, isNonNegative); |
| 213 shouldPass(0, isNonNegative); | 230 shouldPass(0, isNonNegative); |
| 214 shouldFail(-1, isNonNegative, | 231 shouldFail(-1, isNonNegative, |
| 215 "Expected: a non-negative value But: was <-1>. Actual: <-1>"); | 232 "Expected: a non-negative value " |
| 233 "Actual: <-1> " |
| 234 "Which: is not a non-negative value"); |
| 216 }); | 235 }); |
| 217 | 236 |
| 218 test('closeTo', () { | 237 test('closeTo', () { |
| 219 shouldPass(0, closeTo(0, 1)); | 238 shouldPass(0, closeTo(0, 1)); |
| 220 shouldPass(-1, closeTo(0, 1)); | 239 shouldPass(-1, closeTo(0, 1)); |
| 221 shouldPass(1, closeTo(0, 1)); | 240 shouldPass(1, closeTo(0, 1)); |
| 222 shouldFail(1.001, closeTo(0, 1), | 241 shouldFail(1.001, closeTo(0, 1), |
| 223 "Expected: a numeric value within <1> of <0> " | 242 "Expected: a numeric value within <1> of <0> " |
| 224 "But: differed by <1.001>. " | 243 "Actual: <1.001> " |
| 225 "Actual: <1.001>"); | 244 "Which: differs by <1.001>"); |
| 226 shouldFail(-1.001, closeTo(0, 1), | 245 shouldFail(-1.001, closeTo(0, 1), |
| 227 "Expected: a numeric value within <1> of <0> " | 246 "Expected: a numeric value within <1> of <0> " |
| 228 "But: differed by <1.001>. " | 247 "Actual: <-1.001> " |
| 229 "Actual: <-1.001>"); | 248 "Which: differs by <1.001>"); |
| 230 }); | 249 }); |
| 231 | 250 |
| 232 test('inInclusiveRange', () { | 251 test('inInclusiveRange', () { |
| 233 shouldFail(-1, inInclusiveRange(0,2), | 252 shouldFail(-1, inInclusiveRange(0,2), |
| 234 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 253 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
| 235 "But: was <-1>. Actual: <-1>"); | 254 "Actual: <-1>"); |
| 236 shouldPass(0, inInclusiveRange(0,2)); | 255 shouldPass(0, inInclusiveRange(0,2)); |
| 237 shouldPass(1, inInclusiveRange(0,2)); | 256 shouldPass(1, inInclusiveRange(0,2)); |
| 238 shouldPass(2, inInclusiveRange(0,2)); | 257 shouldPass(2, inInclusiveRange(0,2)); |
| 239 shouldFail(3, inInclusiveRange(0,2), | 258 shouldFail(3, inInclusiveRange(0,2), |
| 240 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 259 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
| 241 "But: was <3>. Actual: <3>"); | 260 "Actual: <3>"); |
| 242 }); | 261 }); |
| 243 | 262 |
| 244 test('inExclusiveRange', () { | 263 test('inExclusiveRange', () { |
| 245 shouldFail(0, inExclusiveRange(0,2), | 264 shouldFail(0, inExclusiveRange(0,2), |
| 246 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 265 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
| 247 "But: was <0>. Actual: <0>"); | 266 "Actual: <0>"); |
| 248 shouldPass(1, inExclusiveRange(0,2)); | 267 shouldPass(1, inExclusiveRange(0,2)); |
| 249 shouldFail(2, inExclusiveRange(0,2), | 268 shouldFail(2, inExclusiveRange(0,2), |
| 250 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 269 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
| 251 "But: was <2>. Actual: <2>"); | 270 "Actual: <2>"); |
| 252 }); | 271 }); |
| 253 | 272 |
| 254 test('inOpenClosedRange', () { | 273 test('inOpenClosedRange', () { |
| 255 shouldFail(0, inOpenClosedRange(0,2), | 274 shouldFail(0, inOpenClosedRange(0,2), |
| 256 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " | 275 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " |
| 257 "But: was <0>. Actual: <0>"); | 276 "Actual: <0>"); |
| 258 shouldPass(1, inOpenClosedRange(0,2)); | 277 shouldPass(1, inOpenClosedRange(0,2)); |
| 259 shouldPass(2, inOpenClosedRange(0,2)); | 278 shouldPass(2, inOpenClosedRange(0,2)); |
| 260 }); | 279 }); |
| 261 | 280 |
| 262 test('inClosedOpenRange', () { | 281 test('inClosedOpenRange', () { |
| 263 shouldPass(0, inClosedOpenRange(0,2)); | 282 shouldPass(0, inClosedOpenRange(0,2)); |
| 264 shouldPass(1, inClosedOpenRange(0,2)); | 283 shouldPass(1, inClosedOpenRange(0,2)); |
| 265 shouldFail(2, inClosedOpenRange(0,2), | 284 shouldFail(2, inClosedOpenRange(0,2), |
| 266 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " | 285 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " |
| 267 "But: was <2>. Actual: <2>"); | 286 "Actual: <2>"); |
| 268 }); | 287 }); |
| 269 }); | 288 }); |
| 270 | 289 |
| 271 group('String Matchers', () { | 290 group('String Matchers', () { |
| 272 | 291 |
| 273 test('isEmpty', () { | 292 test('isEmpty', () { |
| 274 shouldPass('', isEmpty); | 293 shouldPass('', isEmpty); |
| 275 shouldFail(null, isEmpty, | 294 shouldFail(null, isEmpty, |
| 276 "Expected: empty But: was <null>. Actual: <null>"); | 295 "Expected: empty Actual: <null>"); |
| 277 shouldFail(0, isEmpty, | 296 shouldFail(0, isEmpty, |
| 278 "Expected: empty But: was <0>. Actual: <0>"); | 297 "Expected: empty Actual: <0>"); |
| 279 shouldFail('a', isEmpty, "Expected: empty But: was 'a'. Actual: 'a'"); | 298 shouldFail('a', isEmpty, "Expected: empty Actual: 'a'"); |
| 280 }); | 299 }); |
| 281 | 300 |
| 282 test('equalsIgnoringCase', () { | 301 test('equalsIgnoringCase', () { |
| 283 shouldPass('hello', equalsIgnoringCase('HELLO')); | 302 shouldPass('hello', equalsIgnoringCase('HELLO')); |
| 284 shouldFail('hi', equalsIgnoringCase('HELLO'), | 303 shouldFail('hi', equalsIgnoringCase('HELLO'), |
| 285 "Expected: 'HELLO' ignoring case But: was 'hi'. Actual: 'hi'"); | 304 "Expected: 'HELLO' ignoring case Actual: 'hi'"); |
| 286 }); | 305 }); |
| 287 | 306 |
| 288 test('equalsIgnoringWhitespace', () { | 307 test('equalsIgnoringWhitespace', () { |
| 289 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); | 308 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); |
| 290 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), | 309 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), |
| 291 "Expected: 'hello world' ignoring whitespace " | 310 "Expected: 'hello world' ignoring whitespace " |
| 292 "But: was 'helloworld'. Actual: ' helloworld '"); | 311 "Actual: ' helloworld ' " |
| 312 "Which: is 'helloworld' with whitespace compressed"); |
| 293 }); | 313 }); |
| 294 | 314 |
| 295 test('startsWith', () { | 315 test('startsWith', () { |
| 296 shouldPass('hello', startsWith('')); | 316 shouldPass('hello', startsWith('')); |
| 297 shouldPass('hello', startsWith('hell')); | 317 shouldPass('hello', startsWith('hell')); |
| 298 shouldPass('hello', startsWith('hello')); | 318 shouldPass('hello', startsWith('hello')); |
| 299 shouldFail('hello', startsWith('hello '), | 319 shouldFail('hello', startsWith('hello '), |
| 300 "Expected: a string starting with 'hello ' " | 320 "Expected: a string starting with 'hello ' " |
| 301 "But: was 'hello'. Actual: 'hello'"); | 321 "Actual: 'hello'"); |
| 302 }); | 322 }); |
| 303 | 323 |
| 304 test('endsWith', () { | 324 test('endsWith', () { |
| 305 shouldPass('hello', endsWith('')); | 325 shouldPass('hello', endsWith('')); |
| 306 shouldPass('hello', endsWith('lo')); | 326 shouldPass('hello', endsWith('lo')); |
| 307 shouldPass('hello', endsWith('hello')); | 327 shouldPass('hello', endsWith('hello')); |
| 308 shouldFail('hello', endsWith(' hello'), | 328 shouldFail('hello', endsWith(' hello'), |
| 309 "Expected: a string ending with ' hello' " | 329 "Expected: a string ending with ' hello' " |
| 310 "But: was 'hello'. Actual: 'hello'"); | 330 "Actual: 'hello'"); |
| 311 }); | 331 }); |
| 312 | 332 |
| 313 test('contains', () { | 333 test('contains', () { |
| 314 shouldPass('hello', contains('')); | 334 shouldPass('hello', contains('')); |
| 315 shouldPass('hello', contains('h')); | 335 shouldPass('hello', contains('h')); |
| 316 shouldPass('hello', contains('o')); | 336 shouldPass('hello', contains('o')); |
| 317 shouldPass('hello', contains('hell')); | 337 shouldPass('hello', contains('hell')); |
| 318 shouldPass('hello', contains('hello')); | 338 shouldPass('hello', contains('hello')); |
| 319 shouldFail('hello', contains(' '), | 339 shouldFail('hello', contains(' '), |
| 320 "Expected: contains ' ' But: was 'hello'. Actual: 'hello'"); | 340 "Expected: contains ' ' Actual: 'hello'"); |
| 321 }); | 341 }); |
| 322 | 342 |
| 323 test('stringContainsInOrder', () { | 343 test('stringContainsInOrder', () { |
| 324 shouldPass('goodbye cruel world', stringContainsInOrder([''])); | 344 shouldPass('goodbye cruel world', stringContainsInOrder([''])); |
| 325 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | 345 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); |
| 326 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | 346 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); |
| 327 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | 347 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); |
| 328 shouldPass('goodbye cruel world', | 348 shouldPass('goodbye cruel world', |
| 329 stringContainsInOrder(['good', 'bye', 'world'])); | 349 stringContainsInOrder(['good', 'bye', 'world'])); |
| 330 shouldPass('goodbye cruel world', | 350 shouldPass('goodbye cruel world', |
| 331 stringContainsInOrder(['goodbye', 'cruel'])); | 351 stringContainsInOrder(['goodbye', 'cruel'])); |
| 332 shouldPass('goodbye cruel world', | 352 shouldPass('goodbye cruel world', |
| 333 stringContainsInOrder(['cruel', 'world'])); | 353 stringContainsInOrder(['cruel', 'world'])); |
| 334 shouldPass('goodbye cruel world', | 354 shouldPass('goodbye cruel world', |
| 335 stringContainsInOrder(['goodbye', 'cruel', 'world'])); | 355 stringContainsInOrder(['goodbye', 'cruel', 'world'])); |
| 336 shouldFail('goodbye cruel world', | 356 shouldFail('goodbye cruel world', |
| 337 stringContainsInOrder(['goo', 'cruel', 'bye']), | 357 stringContainsInOrder(['goo', 'cruel', 'bye']), |
| 338 "Expected: a string containing 'goo', 'cruel', 'bye' in order " | 358 "Expected: a string containing 'goo', 'cruel', 'bye' in order " |
| 339 "But: was 'goodbye cruel world'. Actual: 'goodbye cruel world'"); | 359 "Actual: 'goodbye cruel world'"); |
| 340 }); | 360 }); |
| 341 | 361 |
| 342 test('matches', () { | 362 test('matches', () { |
| 343 shouldPass('c0d', matches('[a-z][0-9][a-z]')); | 363 shouldPass('c0d', matches('[a-z][0-9][a-z]')); |
| 344 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | 364 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); |
| 345 shouldFail('cOd', matches('[a-z][0-9][a-z]'), | 365 shouldFail('cOd', matches('[a-z][0-9][a-z]'), |
| 346 "Expected: match '[a-z][0-9][a-z]' But: was 'cOd'. Actual: 'cOd'"); | 366 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); |
| 347 }); | 367 }); |
| 348 }); | 368 }); |
| 349 | 369 |
| 350 group('Iterable Matchers', () { | 370 group('Iterable Matchers', () { |
| 351 | 371 |
| 352 test('isEmpty', () { | 372 test('isEmpty', () { |
| 353 shouldPass([], isEmpty); | 373 shouldPass([], isEmpty); |
| 354 shouldFail([1], isEmpty, "Expected: empty But: was [1]. Actual: [1]"); | 374 shouldFail([1], isEmpty, "Expected: empty Actual: [1]"); |
| 355 }); | 375 }); |
| 356 | 376 |
| 357 test('contains', () { | 377 test('contains', () { |
| 358 var d = [1, 2]; | 378 var d = [1, 2]; |
| 359 shouldPass(d, contains(1)); | 379 shouldPass(d, contains(1)); |
| 360 shouldFail(d, contains(0), "Expected: contains <0> " | 380 shouldFail(d, contains(0), "Expected: contains <0> " |
| 361 "But: was [1, 2]. Actual: [1, 2]"); | 381 "Actual: [1, 2]"); |
| 362 }); | 382 }); |
| 363 | 383 |
| 364 test('isIn', () { | 384 test('isIn', () { |
| 365 var d = [1, 2]; | 385 var d = [1, 2]; |
| 366 shouldPass(1, isIn(d)); | 386 shouldPass(1, isIn(d)); |
| 367 shouldFail(0, isIn(d), "Expected: is in [1, 2] But: was <0>. Actual: <0>")
; | 387 shouldFail(0, isIn(d), "Expected: is in [1, 2] Actual: <0>"); |
| 368 }); | 388 }); |
| 369 | 389 |
| 370 test('everyElement', () { | 390 test('everyElement', () { |
| 371 var d = [1, 2]; | 391 var d = [1, 2]; |
| 372 var e = [1, 1, 1]; | 392 var e = [1, 1, 1]; |
| 373 shouldFail(d, everyElement(1), | 393 shouldFail(d, everyElement(1), |
| 374 "Expected: every element <1> But: position 1 was <2>. " | 394 "Expected: every element <1> " |
| 375 "Actual: [1, 2]"); | 395 "Actual: [1, 2] " |
| 396 "Which: at position 1 is <2>"); |
| 376 shouldPass(e, everyElement(1)); | 397 shouldPass(e, everyElement(1)); |
| 377 }); | 398 }); |
| 378 | 399 |
| 379 test('someElement', () { | 400 test('someElement', () { |
| 380 var d = [1, 2]; | 401 var d = [1, 2]; |
| 381 var e = [1, 1, 1]; | 402 var e = [1, 1, 1]; |
| 382 shouldPass(d, someElement(2)); | 403 shouldPass(d, someElement(2)); |
| 383 shouldFail(e, someElement(2), | 404 shouldFail(e, someElement(2), |
| 384 "Expected: some element <2> But: was [1, 1, 1]. Actual: [1, 1, 1]"); | 405 "Expected: some element <2> Actual: [1, 1, 1]"); |
| 385 }); | 406 }); |
| 386 | 407 |
| 387 test('orderedEquals', () { | 408 test('orderedEquals', () { |
| 388 shouldPass([null], orderedEquals([null])); | 409 shouldPass([null], orderedEquals([null])); |
| 389 var d = [1, 2]; | 410 var d = [1, 2]; |
| 390 shouldPass(d, orderedEquals([1, 2])); | 411 shouldPass(d, orderedEquals([1, 2])); |
| 391 shouldFail(d, orderedEquals([2, 1]), | 412 shouldFail(d, orderedEquals([2, 1]), |
| 392 "Expected: equals [2, 1] ordered " | 413 "Expected: equals [2, 1] ordered " |
| 393 "But: expected <2> but was <1> mismatch at position 0. " | 414 "Actual: [1, 2] " |
| 394 "Actual: [1, 2]"); | 415 "Which: has mismatch at position 0: expected <2> but is <1>"); |
| 395 }); | 416 }); |
| 396 | 417 |
| 397 test('unorderedEquals', () { | 418 test('unorderedEquals', () { |
| 398 var d = [1, 2]; | 419 var d = [1, 2]; |
| 399 shouldPass(d, unorderedEquals([2, 1])); | 420 shouldPass(d, unorderedEquals([2, 1])); |
| 400 shouldFail(d, unorderedEquals([1]), | 421 shouldFail(d, unorderedEquals([1]), |
| 401 "Expected: equals [1] unordered " | 422 "Expected: equals [1] unordered " |
| 402 "But: has too many elements (2 > 1). " | 423 "Actual: [1, 2] " |
| 403 "Actual: [1, 2]"); | 424 "Which: has too many elements (2 > 1)"); |
| 404 shouldFail(d, unorderedEquals([3, 2, 1]), | 425 shouldFail(d, unorderedEquals([3, 2, 1]), |
| 405 "Expected: equals [3, 2, 1] unordered " | 426 "Expected: equals [3, 2, 1] unordered " |
| 406 "But: has too few elements (2 < 3). " | 427 "Actual: [1, 2] " |
| 407 "Actual: [1, 2]"); | 428 "Which: has too few elements (2 < 3)"); |
| 408 shouldFail(d, unorderedEquals([3, 1]), | 429 shouldFail(d, unorderedEquals([3, 1]), |
| 409 "Expected: equals [3, 1] unordered " | 430 "Expected: equals [3, 1] unordered " |
| 410 "But: has no match for element <3> at position 0. " | 431 "Actual: [1, 2] " |
| 411 "Actual: [1, 2]"); | 432 "Which: has no match for element <3> at position 0"); |
| 412 }); | 433 }); |
| 413 | 434 |
| 414 test('pairwise compare', () { | 435 test('pairwise compare', () { |
| 415 var c = [1, 2]; | 436 var c = [1, 2]; |
| 416 var d = [1, 2, 3]; | 437 var d = [1, 2, 3]; |
| 417 var e = [1, 4, 9]; | 438 var e = [1, 4, 9]; |
| 418 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, | 439 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, |
| 419 "less than or equal"), | 440 "less than or equal"), |
| 420 "Expected: pairwise less than or equal [1, 4, 9] " | 441 "Expected: pairwise less than or equal [1, 4, 9] " |
| 421 "But: not an Iterable. " | 442 "Actual: 'x' " |
| 422 "Actual: 'x'"); | 443 "Which: is not an Iterable"); |
| 423 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), | 444 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), |
| 424 "Expected: pairwise less than or equal [1, 4, 9] " | 445 "Expected: pairwise less than or equal [1, 4, 9] " |
| 425 "But: length was 2 instead of 3. " | 446 "Actual: [1, 2] " |
| 426 "Actual: [1, 2]"); | 447 "Which: has length 2 instead of 3"); |
| 427 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); | 448 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); |
| 428 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), | 449 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), |
| 429 "Expected: pairwise less than [1, 4, 9] " | 450 "Expected: pairwise less than [1, 4, 9] " |
| 430 "But: <1> not less than <1> at position 0. " | 451 "Actual: [1, 2, 3] " |
| 431 "Actual: [1, 2, 3]"); | 452 "Which: has <1> which is not less than <1> at position 0"); |
| 432 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); | 453 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); |
| 433 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), | 454 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), |
| 434 "Expected: pairwise double [1, 4, 9] " | 455 "Expected: pairwise double [1, 4, 9] " |
| 435 "But: <1> not double <1> at position 0. " | 456 "Actual: [1, 2, 3] " |
| 436 "Actual: [1, 2, 3]"); | 457 "Which: has <1> which is not double <1> at position 0"); |
| 437 }); | 458 }); |
| 438 }); | 459 }); |
| 439 | 460 |
| 440 group('Map Matchers', () { | 461 group('Map Matchers', () { |
| 441 | 462 |
| 442 test('isEmpty', () { | 463 test('isEmpty', () { |
| 443 var a = new Map(); | 464 var a = new Map(); |
| 444 shouldPass({}, isEmpty); | 465 shouldPass({}, isEmpty); |
| 445 shouldPass(a, isEmpty); | 466 shouldPass(a, isEmpty); |
| 446 a['foo'] = 'bar'; | 467 a['foo'] = 'bar'; |
| 447 shouldFail(a, isEmpty, "Expected: empty But: was {'foo': 'bar'}. " | 468 shouldFail(a, isEmpty, "Expected: empty " |
| 448 "Actual: {'foo': 'bar'}"); | 469 "Actual: {'foo': 'bar'}"); |
| 449 }); | 470 }); |
| 450 | 471 |
| 451 test('equals', () { | 472 test('equals', () { |
| 452 var a = new Map(); | 473 var a = new Map(); |
| 453 a['foo'] = 'bar'; | 474 a['foo'] = 'bar'; |
| 454 var b = new Map(); | 475 var b = new Map(); |
| 455 b['foo'] = 'bar'; | 476 b['foo'] = 'bar'; |
| 456 var c = new Map(); | 477 var c = new Map(); |
| 457 c['bar'] = 'foo'; | 478 c['bar'] = 'foo'; |
| 458 shouldPass(a, equals(b)); | 479 shouldPass(a, equals(b)); |
| 459 shouldFail(b, equals(c), | 480 shouldFail(b, equals(c), |
| 460 "Expected: {'bar': 'foo'} But: missing map key 'bar'. " | 481 "Expected: {'bar': 'foo'} " |
| 461 "Actual: {'foo': 'bar'}"); | 482 "Actual: {'foo': 'bar'} " |
| 483 "Which: is missing map key 'bar'"); |
| 462 }); | 484 }); |
| 463 | 485 |
| 464 test('equals with different lengths', () { | 486 test('equals with different lengths', () { |
| 465 var a = new LinkedHashMap(); | 487 var a = new LinkedHashMap(); |
| 466 a['foo'] = 'bar'; | 488 a['foo'] = 'bar'; |
| 467 var b = new LinkedHashMap(); | 489 var b = new LinkedHashMap(); |
| 468 b['foo'] = 'bar'; | 490 b['foo'] = 'bar'; |
| 469 b['bar'] = 'foo'; | 491 b['bar'] = 'foo'; |
| 470 var c = new LinkedHashMap(); | 492 var c = new LinkedHashMap(); |
| 471 c['bar'] = 'foo'; | 493 c['bar'] = 'foo'; |
| 472 c['barrista'] = 'caffeine'; | 494 c['barrista'] = 'caffeine'; |
| 473 shouldFail(a, equals(b), | 495 shouldFail(a, equals(b), |
| 474 "Expected: {'foo': 'bar', 'bar': 'foo'} " | 496 "Expected: {'foo': 'bar', 'bar': 'foo'} " |
| 475 "But: different map lengths; missing map key 'bar'. " | 497 "Actual: {'foo': 'bar'} " |
| 476 "Actual: {'foo': 'bar'}"); | 498 "Which: has different length and is missing map key 'bar'"); |
| 477 shouldFail(b, equals(a), | 499 shouldFail(b, equals(a), |
| 478 "Expected: {'foo': 'bar'} " | 500 "Expected: {'foo': 'bar'} " |
| 479 "But: different map lengths; extra map key 'bar'. " | 501 "Actual: {'foo': 'bar', 'bar': 'foo'} " |
| 480 "Actual: {'foo': 'bar', 'bar': 'foo'}"); | 502 "Which: has different length and has extra map key 'bar'"); |
| 481 shouldFail(b, equals(c), | 503 shouldFail(b, equals(c), |
| 482 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " | 504 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 483 "But: missing map key 'barrista'. " | 505 "Actual: {'foo': 'bar', 'bar': 'foo'} " |
| 484 "Actual: {'foo': 'bar', 'bar': 'foo'}"); | 506 "Which: is missing map key 'barrista'"); |
| 485 shouldFail(c, equals(b), | 507 shouldFail(c, equals(b), |
| 486 "Expected: {'foo': 'bar', 'bar': 'foo'} " | 508 "Expected: {'foo': 'bar', 'bar': 'foo'} " |
| 487 "But: missing map key 'foo'. " | 509 "Actual: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 488 "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); | 510 "Which: is missing map key 'foo'"); |
| 489 shouldFail(a, equals(c), | 511 shouldFail(a, equals(c), |
| 490 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " | 512 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 491 "But: different map lengths; missing map key 'bar'. " | 513 "Actual: {'foo': 'bar'} " |
| 492 "Actual: {'foo': 'bar'}"); | 514 "Which: has different length and is missing map key 'bar'"); |
| 493 shouldFail(c, equals(a), | 515 shouldFail(c, equals(a), |
| 494 "Expected: {'foo': 'bar'} " | 516 "Expected: {'foo': 'bar'} " |
| 495 "But: different map lengths; missing map key 'foo'. " | 517 "Actual: {'bar': 'foo', 'barrista': 'caffeine'} " |
| 496 "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); | 518 "Which: has different length and is missing map key 'foo'"); |
| 497 }); | 519 }); |
| 498 | 520 |
| 499 test('contains', () { | 521 test('contains', () { |
| 500 var a = new Map(); | 522 var a = new Map(); |
| 501 a['foo'] = 'bar'; | 523 a['foo'] = 'bar'; |
| 502 var b = new Map(); | 524 var b = new Map(); |
| 503 shouldPass(a, contains('foo')); | 525 shouldPass(a, contains('foo')); |
| 504 shouldFail(b, contains('foo'), | 526 shouldFail(b, contains('foo'), |
| 505 "Expected: contains 'foo' But: was {}. Actual: {}"); | 527 "Expected: contains 'foo' Actual: {}"); |
| 506 shouldFail(10, contains('foo'), | 528 shouldFail(10, contains('foo'), |
| 507 "Expected: contains 'foo' But: was <10>. Actual: <10>"); | 529 "Expected: contains 'foo' Actual: <10>"); |
| 508 }); | 530 }); |
| 509 | 531 |
| 510 test('containsValue', () { | 532 test('containsValue', () { |
| 511 var a = new Map(); | 533 var a = new Map(); |
| 512 a['foo'] = 'bar'; | 534 a['foo'] = 'bar'; |
| 513 shouldPass(a, containsValue('bar')); | 535 shouldPass(a, containsValue('bar')); |
| 514 shouldFail(a, containsValue('ba'), | 536 shouldFail(a, containsValue('ba'), |
| 515 "Expected: contains value 'ba' But: was {'foo': 'bar'}. " | 537 "Expected: contains value 'ba' " |
| 516 "Actual: {'foo': 'bar'}"); | 538 "Actual: {'foo': 'bar'}"); |
| 517 }); | 539 }); |
| 518 | 540 |
| 519 test('containsPair', () { | 541 test('containsPair', () { |
| 520 var a = new Map(); | 542 var a = new Map(); |
| 521 a['foo'] = 'bar'; | 543 a['foo'] = 'bar'; |
| 522 shouldPass(a, containsPair('foo', 'bar')); | 544 shouldPass(a, containsPair('foo', 'bar')); |
| 523 shouldFail(a, containsPair('foo', 'ba'), | 545 shouldFail(a, containsPair('foo', 'ba'), |
| 524 "Expected: contains pair 'foo' => 'ba' " | 546 "Expected: contains pair 'foo' => 'ba' " |
| 525 "But: Strings are not equal. Both strings start the same, " | 547 "Actual: {'foo': 'bar'} " |
| 526 "but the given value also has the following trailing characters: r. " | 548 "Which: is different. Both strings start the same, but " |
| 527 "Actual: {'foo': 'bar'}"); | 549 "the given value also has the following trailing characters: r"); |
| 528 shouldFail(a, containsPair('fo', 'bar'), | 550 shouldFail(a, containsPair('fo', 'bar'), |
| 529 "Expected: contains pair 'fo' => 'bar' " | 551 "Expected: contains pair 'fo' => 'bar' " |
| 530 "But: doesn't contain key 'fo'. " | 552 "Actual: {'foo': 'bar'} " |
| 531 "Actual: {'foo': 'bar'}"); | 553 "Which: doesn't contain key 'fo'"); |
| 532 }); | 554 }); |
| 533 | 555 |
| 534 test('hasLength', () { | 556 test('hasLength', () { |
| 535 var a = new Map(); | 557 var a = new Map(); |
| 536 a['foo'] = 'bar'; | 558 a['foo'] = 'bar'; |
| 537 var b = new Map(); | 559 var b = new Map(); |
| 538 shouldPass(a, hasLength(1)); | 560 shouldPass(a, hasLength(1)); |
| 539 shouldFail(b, hasLength(1), | 561 shouldFail(b, hasLength(1), |
| 540 "Expected: an object with length of <1> " | 562 "Expected: an object with length of <1> " |
| 541 "But: had length of <0>. " | 563 "Actual: {} " |
| 542 "Actual: {}"); | 564 "Which: has length of <0>"); |
| 543 }); | 565 }); |
| 544 }); | 566 }); |
| 545 | 567 |
| 546 group('Operator Matchers', () { | 568 group('Operator Matchers', () { |
| 547 | 569 |
| 548 test('anyOf', () { | 570 test('anyOf', () { |
| 549 shouldFail(0, anyOf([equals(1), equals(2)]), | 571 shouldFail(0, anyOf([equals(1), equals(2)]), |
| 550 "Expected: (<1> or <2>) But: was <0>. Actual: <0>"); | 572 "Expected: (<1> or <2>) Actual: <0>"); |
| 551 shouldPass(1, anyOf([equals(1), equals(2)])); | 573 shouldPass(1, anyOf([equals(1), equals(2)])); |
| 552 }); | 574 }); |
| 553 | 575 |
| 554 test('allOf', () { | 576 test('allOf', () { |
| 555 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); | 577 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); |
| 556 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), | 578 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), |
| 557 "Expected: (a value less than <10> and a value greater than <0>) " | 579 "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>"); | 580 "Actual: <-1> " |
| 581 "Which: is not a value greater than <0>"); |
| 559 }); | 582 }); |
| 560 }); | 583 }); |
| 561 | 584 |
| 562 group('Future Matchers', () { | 585 group('Future Matchers', () { |
| 563 | 586 |
| 564 test('completes - unexpected error', () { | 587 test('completes - unexpected error', () { |
| 565 var completer = new Completer(); | 588 var completer = new Completer(); |
| 566 completer.completeError('X'); | 589 completer.completeError('X'); |
| 567 shouldFail(completer.future, completes, | 590 shouldFail(completer.future, completes, |
| 568 contains('Expected future to complete successfully, ' | 591 contains('Expected future to complete successfully, ' |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 test('throwsA - correct error', () { | 631 test('throwsA - correct error', () { |
| 609 var completer = new Completer(); | 632 var completer = new Completer(); |
| 610 completer.completeError('X'); | 633 completer.completeError('X'); |
| 611 shouldPass(completer.future, throwsA(equals('X')), isAsync: true); | 634 shouldPass(completer.future, throwsA(equals('X')), isAsync: true); |
| 612 }); | 635 }); |
| 613 | 636 |
| 614 test('throwsA - wrong error', () { | 637 test('throwsA - wrong error', () { |
| 615 var completer = new Completer(); | 638 var completer = new Completer(); |
| 616 completer.completeError('X'); | 639 completer.completeError('X'); |
| 617 shouldFail(completer.future, throwsA(equals('Y')), | 640 shouldFail(completer.future, throwsA(equals('Y')), |
| 618 "Expected: 'Y' But: Strings are not equal. " | 641 "Expected: 'Y' Actual: 'X' " |
| 619 "Expected: Y Actual: X ^ Differ at position 0. Actual: 'X'", | 642 "Which: is different. " |
| 643 "Expected: Y Actual: X ^ Differ at position 0", |
| 620 isAsync: true); | 644 isAsync: true); |
| 621 }); | 645 }); |
| 622 }); | 646 }); |
| 623 | 647 |
| 624 group('Predicate Matchers', () { | 648 group('Predicate Matchers', () { |
| 625 test('isInstanceOf', () { | 649 test('isInstanceOf', () { |
| 626 shouldFail(0, predicate((x) => x is String, "an instance of String"), | 650 shouldFail(0, predicate((x) => x is String, "an instance of String"), |
| 627 "Expected: an instance of String But: was <0>. Actual: <0>"); | 651 "Expected: an instance of String Actual: <0>"); |
| 628 shouldPass('cow', predicate((x) => x is String, "an instance of String")); | 652 shouldPass('cow', predicate((x) => x is String, "an instance of String")); |
| 629 }); | 653 }); |
| 630 }); | 654 }); |
| 631 } | 655 } |
| 632 | 656 |
| OLD | NEW |