| 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 library matcher.operator_matchers; | 5 library matcher.operator_matchers; |
| 6 | 6 |
| 7 import 'core_matchers.dart'; | |
| 8 import 'expect.dart'; | |
| 9 import 'interfaces.dart'; | 7 import 'interfaces.dart'; |
| 8 import 'util.dart'; |
| 10 | 9 |
| 11 /// This returns a matcher that inverts [matcher] to its logical negation. | 10 /// This returns a matcher that inverts [matcher] to its logical negation. |
| 12 Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher)); | 11 Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher)); |
| 13 | 12 |
| 14 class _IsNot extends Matcher { | 13 class _IsNot extends Matcher { |
| 15 final Matcher _matcher; | 14 final Matcher _matcher; |
| 16 | 15 |
| 17 const _IsNot(Matcher this._matcher); | 16 const _IsNot(this._matcher); |
| 18 | 17 |
| 19 bool matches(item, Map matchState) => !_matcher.matches(item, matchState); | 18 bool matches(item, Map matchState) => !_matcher.matches(item, matchState); |
| 20 | 19 |
| 21 Description describe(Description description) => | 20 Description describe(Description description) => |
| 22 description.add('not ').addDescriptionOf(_matcher); | 21 description.add('not ').addDescriptionOf(_matcher); |
| 23 } | 22 } |
| 24 | 23 |
| 25 /// This returns a matcher that matches if all of the matchers passed as | 24 /// This returns a matcher that matches if all of the matchers passed as |
| 26 /// arguments (up to 7) match. Instead of passing the matchers separately | 25 /// arguments (up to 7) match. Instead of passing the matchers separately |
| 27 /// they can be passed as a single List argument. | 26 /// they can be passed as a single List argument. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 return false; | 97 return false; |
| 99 } | 98 } |
| 100 | 99 |
| 101 Description describe(Description description) => | 100 Description describe(Description description) => |
| 102 description.addAll('(', ' or ', ')', _matchers); | 101 description.addAll('(', ' or ', ')', _matchers); |
| 103 } | 102 } |
| 104 | 103 |
| 105 List<Matcher> _wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6) { | 104 List<Matcher> _wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6) { |
| 105 Iterable<Matcher> matchers; |
| 106 if (arg0 is List) { | 106 if (arg0 is List) { |
| 107 // TODO(kevmoo) throw a more helpful error here if any of these args is | 107 if (arg1 != null || arg2 != null || arg3 != null || arg4 != null || |
| 108 // not null | 108 arg5 != null || arg6 != null) { |
| 109 expect(arg1, isNull); | 109 throw new ArgumentError('If arg0 is a List, all other arguments must be' |
| 110 expect(arg2, isNull); | 110 ' null.'); |
| 111 expect(arg3, isNull); | 111 } |
| 112 expect(arg4, isNull); | |
| 113 expect(arg5, isNull); | |
| 114 expect(arg6, isNull); | |
| 115 | 112 |
| 116 return arg0.map((a) => wrapMatcher(a)).toList(); | 113 matchers = arg0; |
| 114 } else { |
| 115 matchers = [arg0, arg1, arg2, arg3, arg4, arg5, arg6] |
| 116 .where((e) => e != null); |
| 117 } | 117 } |
| 118 | 118 |
| 119 List matchers = new List(); | 119 return matchers |
| 120 if (arg0 != null) { | 120 .map((e) => wrapMatcher(e)) |
| 121 matchers.add(wrapMatcher(arg0)); | 121 .toList(); |
| 122 } | |
| 123 if (arg1 != null) { | |
| 124 matchers.add(wrapMatcher(arg1)); | |
| 125 } | |
| 126 if (arg2 != null) { | |
| 127 matchers.add(wrapMatcher(arg2)); | |
| 128 } | |
| 129 if (arg3 != null) { | |
| 130 matchers.add(wrapMatcher(arg3)); | |
| 131 } | |
| 132 if (arg4 != null) { | |
| 133 matchers.add(wrapMatcher(arg4)); | |
| 134 } | |
| 135 if (arg5 != null) { | |
| 136 matchers.add(wrapMatcher(arg5)); | |
| 137 } | |
| 138 if (arg6 != null) { | |
| 139 matchers.add(wrapMatcher(arg6)); | |
| 140 } | |
| 141 return matchers; | |
| 142 } | 122 } |
| OLD | NEW |