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