| // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| import 'package:analyzer/error/error.dart'; |
| import 'package:linter/src/test_utilities/annotation.dart'; |
| import 'package:test/test.dart'; |
| |
| AnnotationMatcher matchesAnnotation( |
| String? message, ErrorType type, int lineNumber) => |
| AnnotationMatcher(Annotation(message, type, lineNumber)); |
| |
| class AnnotationMatcher extends Matcher { |
| final Annotation _expected; |
| |
| AnnotationMatcher(this._expected); |
| |
| @override |
| Description describe(Description description) => |
| description.addDescriptionOf(_expected); |
| |
| @override |
| bool matches(item, Map matchState) => item is Annotation && _matches(item); |
| |
| bool _matches(Annotation other) { |
| // Only test messages if they're specified in the expectation |
| if (_expected.message != null) { |
| if (_expected.message != other.message) { |
| return false; |
| } |
| } |
| // Similarly for highlighting |
| if (_expected.column != null) { |
| if (_expected.column != other.column || |
| _expected.length != other.length) { |
| return false; |
| } |
| } |
| return _expected.type == other.type && |
| _expected.lineNumber == other.lineNumber; |
| } |
| } |