UNPKG

1.4 kBJavaScriptView Raw
1import { SyntaxTree } from '../es6/lattice'
2import { parse } from 'graphql'
3
4describe('validate IDL -> AST -> IDL works properly', () => {
5 it('Should convert simple IDL to AST and back', () => {
6 const IDL = `
7 type Person {
8 name: String
9 job: String
10 }
11
12 type Query {
13 person: Person
14 }
15 `
16
17 const tree = new SyntaxTree(IDL);
18 const ast = tree.ast;
19
20 expect(Object.keys(ast).length).toBeGreaterThan(0)
21 expect(tree.toString().replace(/\s/g, '')).toEqual(IDL.replace(/\s/g, ''))
22 })
23})
24
25describe('Validate search static methods of SyntaxTree work properly', () => {
26 const ast = parse(`
27 type Person {
28 name: String
29 job: String
30 status: Status
31 }
32
33 enum Status {
34 SINGLE,
35 MARRIED,
36 DIVORCED
37 }
38 `)
39
40 it('should be able to find an object type definition', () => {
41 const node = SyntaxTree.findDefinition(ast, 'Person');
42 expect(node).not.toBeNull();
43 expect(node.name.value).toBe('Person')
44 })
45
46 it('should return null for a non-existent node', () => {
47 const node = SyntaxTree.findDefinition(ast, 'Employee');
48 expect(node).toBeNull();
49 })
50
51 it('should be able to find an enum by value', () => {
52 const node = SyntaxTree.findEnumDefinition(ast, 'Status', 'MARRIED')
53 expect(node).not.toBeNull();
54 expect(node.name.value).toBe('MARRIED')
55 })
56})
57