Skip to content

Commit 5aa6166

Browse files
committed
Test coverage
1 parent 7324a50 commit 5aa6166

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/language/__tests__/parser-test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { kitchenSinkQuery } from '../../__testUtils__/kitchenSinkQuery';
88
import { inspect } from '../../jsutils/inspect';
99

1010
import { Kind } from '../kinds';
11+
import { Lexer } from '../lexer';
1112
import {
1213
parse,
1314
parseConstValue,
15+
Parser,
1416
parseSchemaCoordinate,
1517
parseType,
1618
parseValue,
@@ -115,6 +117,18 @@ describe('Parser', () => {
115117
);
116118
});
117119

120+
it('forbids maxTokens and lexer together', () => {
121+
expect(
122+
() =>
123+
new Parser('{a}', {
124+
maxTokens: 10,
125+
lexer: new Lexer(new Source('{a}')),
126+
}),
127+
).to.throw(
128+
'Setting maxTokens has no effect when a custom lexer is supplied',
129+
);
130+
});
131+
118132
it('parses variable inline values', () => {
119133
expect(() =>
120134
parse('{ field(complex: { a: { b: [ $var ] } }) }'),

src/language/__tests__/schemaCoordinateLexer-test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, it } from 'mocha';
33

44
import { expectToThrowJSON } from '../../__testUtils__/expectJSON';
55

6+
import type { Token } from '../ast';
67
import { SchemaCoordinateLexer } from '../schemaCoordinateLexer';
78
import { Source } from '../source';
89
import { TokenKind } from '../tokenKind';
@@ -49,4 +50,13 @@ describe('SchemaCoordinateLexer', () => {
4950
locations: [{ line: 1, column: 4 }],
5051
});
5152
});
53+
54+
it('counts tokens', () => {
55+
const lexer = new SchemaCoordinateLexer(new Source('Name.field'));
56+
let token: Token;
57+
do {
58+
token = lexer.advance();
59+
} while (token.kind !== TokenKind.EOF);
60+
expect(lexer.tokenCount).to.eq(3);
61+
});
5262
});

src/language/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export class Parser {
247247
if (lexer) {
248248
if (options.maxTokens != null) {
249249
throw new Error(
250-
'Setting maxTokens has no effect when a custom lexer is passed',
250+
'Setting maxTokens has no effect when a custom lexer is supplied',
251251
);
252252
}
253253
this._lexer = lexer;

0 commit comments

Comments
 (0)