platform/packages/jael/jael2/test/text/common.dart

25 lines
631 B
Dart
Raw Normal View History

2017-09-29 22:39:37 +00:00
import 'package:matcher/matcher.dart';
import 'package:jael/src/ast/token.dart';
2021-04-28 00:37:33 +00:00
Matcher isToken(TokenType type, [String? text]) => _IsToken(type, text);
2017-09-29 22:39:37 +00:00
class _IsToken extends Matcher {
final TokenType type;
2021-04-28 00:37:33 +00:00
final String? text;
2017-09-29 22:39:37 +00:00
_IsToken(this.type, [this.text]);
@override
Description describe(Description description) {
if (text == null) return description.add('has type $type');
return description.add('has type $type and text "$text"');
}
@override
bool matches(item, Map matchState) {
return item is Token &&
item.type == type &&
2021-04-29 07:21:31 +00:00
(text == null || item.span.text == text);
2017-09-29 22:39:37 +00:00
}
}