OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library stack_trace.test.utils; | |
6 | |
7 import 'package:test/test.dart'; | 5 import 'package:test/test.dart'; |
8 | 6 |
9 /// Returns a matcher that runs [matcher] against a [Frame]'s `member` field. | 7 /// Returns a matcher that runs [matcher] against a [Frame]'s `member` field. |
10 Matcher frameMember(matcher) => | 8 Matcher frameMember(matcher) => |
11 transform((frame) => frame.member, matcher, 'member'); | 9 transform((frame) => frame.member, matcher, 'member'); |
12 | 10 |
13 /// Returns a matcher that runs [matcher] against a [Frame]'s `library` field. | 11 /// Returns a matcher that runs [matcher] against a [Frame]'s `library` field. |
14 Matcher frameLibrary(matcher) => | 12 Matcher frameLibrary(matcher) => |
15 transform((frame) => frame.library, matcher, 'library'); | 13 transform((frame) => frame.library, matcher, 'library'); |
16 | 14 |
17 /// Returns a matcher that runs [transformation] on its input, then matches | 15 /// Returns a matcher that runs [transformation] on its input, then matches |
18 /// the output against [matcher]. | 16 /// the output against [matcher]. |
19 /// | 17 /// |
20 /// [description] should be a noun phrase that describes the relation of the | 18 /// [description] should be a noun phrase that describes the relation of the |
21 /// output of [transformation] to its input. | 19 /// output of [transformation] to its input. |
22 Matcher transform(transformation(value), matcher, String description) => | 20 Matcher transform(transformation(value), matcher, String description) => |
23 new _TransformMatcher(transformation, wrapMatcher(matcher), description); | 21 new _TransformMatcher(transformation, wrapMatcher(matcher), description); |
24 | 22 |
25 class _TransformMatcher extends Matcher { | 23 class _TransformMatcher extends Matcher { |
26 final Function _transformation; | 24 final Function _transformation; |
27 final Matcher _matcher; | 25 final Matcher _matcher; |
28 final String _description; | 26 final String _description; |
29 | 27 |
30 _TransformMatcher(this._transformation, this._matcher, this._description); | 28 _TransformMatcher(this._transformation, this._matcher, this._description); |
31 | 29 |
32 bool matches(item, Map matchState) => | 30 bool matches(item, Map matchState) => |
33 _matcher.matches(_transformation(item), matchState); | 31 _matcher.matches(_transformation(item), matchState); |
34 | 32 |
35 Description describe(Description description) => | 33 Description describe(Description description) => |
36 description.add(_description).add(' ').addDescriptionOf(_matcher); | 34 description.add(_description).add(' ').addDescriptionOf(_matcher); |
37 } | 35 } |
OLD | NEW |