Skip to content

Commit 30922d3

Browse files
committed
Add SchemaCoordinateLexer test
1 parent df9829a commit 30922d3

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/language/__tests__/lexer-test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import { inspect } from '../../jsutils/inspect.js';
99
import { GraphQLError } from '../../error/GraphQLError.js';
1010

1111
import type { Token } from '../ast.js';
12-
import { isPunctuatorTokenKind, Lexer } from '../lexer.js';
12+
import {
13+
isPunctuatorTokenKind,
14+
Lexer,
15+
SchemaCoordinateLexer,
16+
} from '../lexer.js';
1317
import { Source } from '../source.js';
1418
import { TokenKind } from '../tokenKind.js';
1519

@@ -1189,6 +1193,33 @@ describe('Lexer', () => {
11891193
});
11901194
});
11911195

1196+
describe('SchemaCoordinateLexer', () => {
1197+
it('can be stringified', () => {
1198+
const lexer = new SchemaCoordinateLexer(new Source('Name.field'));
1199+
expect(Object.prototype.toString.call(lexer)).to.equal(
1200+
'[object SchemaCoordinateLexer]',
1201+
);
1202+
});
1203+
1204+
it('tracks a schema coordinate', () => {
1205+
const lexer = new SchemaCoordinateLexer(new Source('Name.field'));
1206+
expect(lexer.advance()).to.contain({
1207+
kind: TokenKind.NAME,
1208+
start: 0,
1209+
end: 4,
1210+
value: 'Name',
1211+
});
1212+
});
1213+
1214+
it('forbids ignored tokens', () => {
1215+
const lexer = new SchemaCoordinateLexer(new Source('\nName.field'));
1216+
expectToThrowJSON(() => lexer.advance()).to.deep.equal({
1217+
message: 'Syntax Error: Invalid character: U+000A.',
1218+
locations: [{ line: 1, column: 1 }],
1219+
});
1220+
});
1221+
});
1222+
11921223
describe('isPunctuatorTokenKind', () => {
11931224
function isPunctuatorToken(text: string) {
11941225
return isPunctuatorTokenKind(lexOne(text).kind);

0 commit comments

Comments
 (0)