Line data Source code
1 : // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file 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. 4 : 5 : import 'interfaces.dart'; 6 : import 'type_matcher.dart'; 7 : 8 : /// A package-private [TypeMatcher] implementation that makes it easy for 9 : /// subclasses to validate aspects of specific types while providing consistent 10 : /// type checking. 11 : abstract class FeatureMatcher<T> extends TypeMatcher<T> { 12 18 : const FeatureMatcher(); 13 : 14 7 : @override 15 : bool matches(dynamic item, Map matchState) => 16 14 : super.matches(item, matchState) && typedMatches(item as T, matchState); 17 : 18 : bool typedMatches(T item, Map matchState); 19 : 20 0 : @override 21 : Description describeMismatch(Object? item, Description mismatchDescription, 22 : Map matchState, bool verbose) { 23 0 : if (item is T) { 24 0 : return describeTypedMismatch( 25 : item, mismatchDescription, matchState, verbose); 26 : } 27 : 28 0 : return super.describe(mismatchDescription.add('not an ')); 29 : } 30 : 31 0 : Description describeTypedMismatch(T item, Description mismatchDescription, 32 : Map matchState, bool verbose) => 33 : mismatchDescription; 34 : }