-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtraversal.test.ts
77 lines (61 loc) · 2.6 KB
/
traversal.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import t from 'tap'
import type {ExprNode} from '../src/nodeTypes'
import {
type TraversalResult,
traverseArray,
traverseElement,
traversePlain,
traverseProjection,
} from '../src/traversal'
import {throwsWithMessage} from './testUtils'
t.test('traverseProjection', async (t) => {
t.test('throws when the right hand side type is unknown', async (t) => {
const traversal = () => {
return {type: 'Tuple', members: []} as ExprNode
}
// @ts-ignore (we intentionally want to use an invalid `type` property for testing purposes)
const right = {type: 'c-c', build: traversal} as TraversalResult
throwsWithMessage(t, () => traverseProjection(traversal, right), 'unknown type: c-c')
})
t.test('handles `b-a` type traversals correctly', async (t) => {
const traversal = () => {
return {type: 'Tuple', members: []} as ExprNode
}
const right = {type: 'b-a', build: traversal} as TraversalResult
const finalTraversalResult = traverseProjection(traversal, right)
t.same(finalTraversalResult.type, 'b-a')
// This is a slightly hacky way to test that the `build` property is a Traversal,
// since traversals are just a type of function.
t.type(finalTraversalResult.build, 'function')
})
})
t.test('traverseElement', async (t) => {
t.test('throws when the right hand side type is unknown', async (t) => {
const traversal = () => {
return {type: 'Tuple', members: []} as ExprNode
}
// @ts-ignore (we intentionally want to use an invalid `type` property for testing purposes)
const right = {type: 'c-c', build: traversal} as TraversalResult
throwsWithMessage(t, () => traverseElement(traversal, right), 'unknown type: c-c')
})
})
t.test('traversePlain', async (t) => {
t.test('throws when the right hand side type is unknown', async (t) => {
const traversal = () => {
return {type: 'Tuple', members: []} as ExprNode
}
// @ts-ignore (we intentionally want to use an invalid `type` property for testing purposes)
const right = {type: 'c-c', build: traversal} as TraversalResult
throwsWithMessage(t, () => traversePlain(traversal, right), 'unknown type: c-c')
})
})
t.test('traverseArray', async (t) => {
t.test('throws when the right hand side type is unknown', async (t) => {
const traversal = () => {
return {type: 'Tuple', members: []} as ExprNode
}
// @ts-ignore (we intentionally want to use an invalid `type` property for testing purposes)
const right = {type: 'c-c', build: traversal} as TraversalResult
throwsWithMessage(t, () => traverseArray(traversal, right), 'unknown type: c-c')
})
})