2017-07-04 16:46:01 +00:00
|
|
|
import 'package:graphql_parser/graphql_parser.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'common.dart';
|
|
|
|
import 'argument_test.dart';
|
|
|
|
import 'directive_test.dart';
|
|
|
|
|
|
|
|
main() {
|
|
|
|
test('name only', () {
|
|
|
|
expect(['...foo', '... foo'], everyElement(isFragmentSpread('foo')));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('with directives', () {
|
|
|
|
expect(
|
|
|
|
'... foo @bar @baz: 2 @quux(one: 1)',
|
|
|
|
isFragmentSpread('foo',
|
|
|
|
directives: isDirectiveList([
|
|
|
|
isDirective('bar'),
|
|
|
|
isDirective('baz', valueOrVariable: equals(2)),
|
|
|
|
isDirective('quux', argument: isArgument('one', 1))
|
|
|
|
])));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
FragmentSpreadContext parseFragmentSpread(String text) =>
|
|
|
|
parse(text).parseFragmentSpread();
|
|
|
|
|
|
|
|
Matcher isFragmentSpread(String name, {Matcher directives}) =>
|
2019-08-08 02:24:19 +00:00
|
|
|
_IsFragmentSpread(name, directives);
|
2017-07-04 16:46:01 +00:00
|
|
|
|
|
|
|
class _IsFragmentSpread extends Matcher {
|
|
|
|
final String name;
|
|
|
|
final Matcher directives;
|
|
|
|
|
|
|
|
_IsFragmentSpread(this.name, this.directives);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Description describe(Description description) {
|
|
|
|
if (directives != null)
|
|
|
|
return directives.describe(
|
|
|
|
description.add('is a fragment spread named "$name" that also '));
|
|
|
|
return description.add('is a fragment spread named "$name"');
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool matches(item, Map matchState) {
|
2018-08-04 19:18:53 +00:00
|
|
|
var spread = item is FragmentSpreadContext
|
|
|
|
? item
|
|
|
|
: parseFragmentSpread(item.toString());
|
2017-07-04 16:46:01 +00:00
|
|
|
if (spread == null) return false;
|
|
|
|
if (spread.name != name) return false;
|
|
|
|
if (directives != null)
|
|
|
|
return directives.matches(spread.directives, matchState);
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|