OLD | NEW |
---|---|
1 library typed_mock; | 1 library typed_mock; |
2 | 2 |
3 | 3 |
4 _InvocationMatcher _lastMatcher; | 4 _InvocationMatcher _lastMatcher; |
5 | 5 |
6 /// Enables stubbing methods. | 6 /// Enables stubbing methods. |
7 /// | 7 /// |
8 /// Use it when you want the mock to return a particular value when a particular | 8 /// Use it when you want the mock to return a particular value when a particular |
9 /// method, getter or setter is called. | 9 /// method, getter or setter is called. |
10 /// | 10 /// |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 final List<ArgumentMatcher> _matchers = []; | 108 final List<ArgumentMatcher> _matchers = []; |
109 | 109 |
110 Behavior _behavior; | 110 Behavior _behavior; |
111 | 111 |
112 _InvocationMatcher(this._mock, this._member, Invocation invocation) { | 112 _InvocationMatcher(this._mock, this._member, Invocation invocation) { |
113 invocation.positionalArguments.forEach((argument) { | 113 invocation.positionalArguments.forEach((argument) { |
114 ArgumentMatcher matcher; | 114 ArgumentMatcher matcher; |
115 if (argument is ArgumentMatcher) { | 115 if (argument is ArgumentMatcher) { |
116 matcher = argument; | 116 matcher = argument; |
117 } else { | 117 } else { |
118 matcher = equals(argument); | 118 matcher = new _ArgumentMatcher_equals(argument); |
119 } | 119 } |
120 _matchers.add(matcher); | 120 _matchers.add(matcher); |
121 }); | 121 }); |
122 } | 122 } |
123 | 123 |
124 bool match(Invocation invocation) { | 124 bool match(Invocation invocation) { |
125 var arguments = invocation.positionalArguments; | 125 var arguments = invocation.positionalArguments; |
126 if (arguments.length != _matchers.length) { | 126 if (arguments.length != _matchers.length) { |
127 return false; | 127 return false; |
128 } | 128 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 final expected; | 373 final expected; |
374 | 374 |
375 _ArgumentMatcher_equals(this.expected); | 375 _ArgumentMatcher_equals(this.expected); |
376 | 376 |
377 @override | 377 @override |
378 bool matches(val) { | 378 bool matches(val) { |
379 return val == expected; | 379 return val == expected; |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
383 /// Matches an argument that is equal to the given [expected] value. | |
384 equals(expected) { | |
385 return new _ArgumentMatcher_equals(expected); | |
386 } | |
387 | |
388 | 383 |
389 class _ArgumentMatcher_anyBool extends ArgumentMatcher { | 384 class _ArgumentMatcher_anyBool extends ArgumentMatcher { |
390 @override | 385 @override |
391 bool matches(val) { | 386 bool matches(val) { |
392 return val is bool; | 387 return val is bool; |
393 } | 388 } |
394 } | 389 } |
395 | 390 |
396 /// Matches any [bool] value. | 391 /// Matches any [bool] value. |
397 final anyBool = new _ArgumentMatcher_anyBool(); | 392 final anyBool = new _ArgumentMatcher_anyBool() as dynamic; |
kevmoo
2014/06/03 23:50:09
Doesn't typing the final as 'dynamic' accomplish t
| |
398 | 393 |
399 | 394 |
400 class _ArgumentMatcher_anyInt extends ArgumentMatcher { | 395 class _ArgumentMatcher_anyInt extends ArgumentMatcher { |
401 @override | 396 @override |
402 bool matches(val) { | 397 bool matches(val) { |
403 return val is int; | 398 return val is int; |
404 } | 399 } |
405 } | 400 } |
406 | 401 |
407 /// Matches any [int] value. | 402 /// Matches any [int] value. |
408 final anyInt = new _ArgumentMatcher_anyInt(); | 403 final anyInt = new _ArgumentMatcher_anyInt() as dynamic; |
409 | 404 |
410 | 405 |
411 class _ArgumentMatcher_anyObject extends ArgumentMatcher { | 406 class _ArgumentMatcher_anyObject extends ArgumentMatcher { |
412 @override | 407 @override |
413 bool matches(val) { | 408 bool matches(val) { |
414 return true; | 409 return true; |
415 } | 410 } |
416 } | 411 } |
417 | 412 |
418 /// Matches any [Object] (or subclass) value. | 413 /// Matches any [Object] (or subclass) value. |
419 final anyObject = new _ArgumentMatcher_anyObject(); | 414 final anyObject = new _ArgumentMatcher_anyObject() as dynamic; |
420 | 415 |
421 | 416 |
422 class _ArgumentMatcher_anyString extends ArgumentMatcher { | 417 class _ArgumentMatcher_anyString extends ArgumentMatcher { |
423 @override | 418 @override |
424 bool matches(val) { | 419 bool matches(val) { |
425 return val is String; | 420 return val is String; |
426 } | 421 } |
427 } | 422 } |
428 | 423 |
429 /// Matches any [String] value. | 424 /// Matches any [String] value. |
430 final anyString = new _ArgumentMatcher_anyString(); | 425 final anyString = new _ArgumentMatcher_anyString() as dynamic; |
OLD | NEW |