From de6c9f5bef752ef5944e2ecbe982adae69826a57 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 31 Mar 2019 16:21:11 -0400 Subject: [PATCH] Add next_name_test --- graphql_parser/lib/src/language/parser.dart | 1 + graphql_parser/test/next_name_test.dart | 18 ++++++++++++++++++ graphql_parser/test/selection_set_test.dart | 5 +++++ 3 files changed, 24 insertions(+) create mode 100644 graphql_parser/test/next_name_test.dart diff --git a/graphql_parser/lib/src/language/parser.dart b/graphql_parser/lib/src/language/parser.dart index 517904af..7724b9c1 100644 --- a/graphql_parser/lib/src/language/parser.dart +++ b/graphql_parser/lib/src/language/parser.dart @@ -27,6 +27,7 @@ class Parser { bool nextName(String name) { var tok = peek(); + if (tok?.type == TokenType.NAME && tok.span.text == name) { return next(TokenType.NAME); } diff --git a/graphql_parser/test/next_name_test.dart b/graphql_parser/test/next_name_test.dart new file mode 100644 index 00000000..56d1d046 --- /dev/null +++ b/graphql_parser/test/next_name_test.dart @@ -0,0 +1,18 @@ +import 'package:test/test.dart'; +import 'common.dart'; + +var githubSrc = r''' +query searchRepos($queryString: String!, $repositoryOrder: RepositoryOrder, $first: Int!) { + search(type: REPOSITORY, query: $queryString, first: $first) { + ...SearchResultItemConnection + } +} +'''; + +void main() { + test('can parse formerly-reserved words', () { + var def = parse(githubSrc).parseOperationDefinition(); + expect(def.isQuery, isTrue); + print(def.variableDefinitions); + }); +} diff --git a/graphql_parser/test/selection_set_test.dart b/graphql_parser/test/selection_set_test.dart index 9e9189f9..34a8bc6f 100644 --- a/graphql_parser/test/selection_set_test.dart +++ b/graphql_parser/test/selection_set_test.dart @@ -73,6 +73,11 @@ class _IsSelectionSet extends Matcher { bool matches(item, Map matchState) { var set = item is SelectionSetContext ? item : parseSelectionSet(item.toString()); + print('Item: $set has ${set.selections.length} selection(s):'); + for (var s in set.selections) { + print(' * $s (${s.span.text})'); + } + if (set == null) return false; if (set.selections.length != selections.length) return false;