Skip to content

Commit 68d8b53

Browse files
committed
Added parser tests back in
1 parent cedea80 commit 68d8b53

File tree

2 files changed

+148
-159
lines changed

2 files changed

+148
-159
lines changed

tests/filter.spec.js

+147-139
Original file line numberDiff line numberDiff line change
@@ -4,188 +4,196 @@ import yank from '../src/yank.js'
44
import data from './data.json'
55

66
describe('src/filter', () => {
7-
describe('as', () => {
8-
it('should set node.key.name to the argument given', () => {
9-
const name = 'test-name'
10-
const node = {
11-
key: {
12-
name: null
7+
describe('filters', () => {
8+
describe('as', () => {
9+
it('should set node.key.name to the argument given', () => {
10+
const name = 'test-name'
11+
const node = {
12+
key: {
13+
name: null
14+
}
1315
}
14-
}
15-
16-
filters.as({
17-
node,
18-
data,
19-
flag: null,
20-
args: [
21-
name
22-
]
23-
})
2416

25-
expect(node.key.name).toEqual(name)
26-
})
17+
filters.as({
18+
node,
19+
data,
20+
flag: null,
21+
args: [
22+
name
23+
]
24+
})
25+
26+
expect(node.key.name).toEqual(name)
27+
})
2728

28-
it('should rename a property after picking it from a data object', () => {
29-
const result = yank(data, `
29+
it('should rename a property after picking it from a data object', () => {
30+
const result = yank(data, `
3031
dateOfBirth | as(dob)
3132
`)
3233

33-
expect(result).toEqual({
34-
dob: data.dateOfBirth
34+
expect(result).toEqual({
35+
dob: data.dateOfBirth
36+
})
3537
})
3638
})
37-
})
3839

39-
describe('nullable', () => {
40-
it('should set node.options.nullable to true', () => {
41-
const node = {
42-
options: {
43-
nullable: false
40+
describe('nullable', () => {
41+
it('should set node.options.nullable to true', () => {
42+
const node = {
43+
options: {
44+
nullable: false
45+
}
4446
}
45-
}
46-
47-
filters.nullable({
48-
node,
49-
data,
50-
flag: {
51-
on: jest.fn()
52-
},
53-
args: []
54-
})
5547

56-
expect(node.options.nullable).toBe(true)
57-
})
48+
filters.nullable({
49+
node,
50+
data,
51+
flag: {
52+
on: jest.fn()
53+
},
54+
args: []
55+
})
5856

59-
it('MACRO flag should set all children to nullable', () => {
60-
const node = {
61-
options: {
62-
nullable: true
63-
},
64-
children: [
65-
{
66-
options: {
67-
nullable: false
68-
}
57+
expect(node.options.nullable).toBe(true)
58+
})
59+
60+
it('MACRO flag should set all children to nullable', () => {
61+
const node = {
62+
options: {
63+
nullable: true
6964
},
70-
{
71-
options: {
72-
nullable: false
65+
children: [
66+
{
67+
options: {
68+
nullable: false
69+
}
70+
},
71+
{
72+
options: {
73+
nullable: false
74+
}
7375
}
74-
}
75-
]
76-
}
77-
78-
filters.nullable({
79-
node,
80-
data,
81-
args: [],
82-
flag: {
83-
on: (_, cb) => cb()
76+
]
8477
}
85-
})
8678

87-
expect(node.options.nullable).toBe(true)
88-
expect(node.children.every(c => c.options.nullable === true)).toBe(true)
89-
})
79+
filters.nullable({
80+
node,
81+
data,
82+
args: [],
83+
flag: {
84+
on: (_, cb) => cb()
85+
}
86+
})
87+
88+
expect(node.options.nullable).toBe(true)
89+
expect(node.children.every(c => c.options.nullable === true)).toBe(true)
90+
})
9091

91-
it('should set undefined values to null', () => {
92-
const result = yank(data, `
92+
it('should set undefined values to null', () => {
93+
const result = yank(data, `
9394
noValueHere | nullable,
94-
alsoNoValueHere
95-
`)
95+
alsoNoValueHere
96+
`)
9697

97-
expect(result.alsoNoValueHere).toBeUndefined()
98-
expect(result).toEqual({
99-
noValueHere: null
98+
expect(result.alsoNoValueHere).toBeUndefined()
99+
expect(result).toEqual({
100+
noValueHere: null
101+
})
100102
})
101103
})
102-
})
103104

104-
describe('extract', () => {
105-
it('should set node.options.extract to true', () => {
106-
const node = {
107-
options: {
108-
extract: false
105+
describe('extract', () => {
106+
it('should set node.options.extract to true', () => {
107+
const node = {
108+
options: {
109+
extract: false
110+
}
109111
}
110-
}
111112

112-
filters.extract({
113-
node,
114-
data,
115-
args: [],
116-
flag: null
117-
})
113+
filters.extract({
114+
node,
115+
data,
116+
args: [],
117+
flag: null
118+
})
118119

119-
expect(node.options.extract).toBe(true)
120-
})
120+
expect(node.options.extract).toBe(true)
121+
})
121122

122-
it('should merge current depth of values into parent depth', () => {
123-
const result = yank(data, `
123+
it('should merge current depth of values into parent depth', () => {
124+
const result = yank(data, `
124125
addressDetails | extract: {
125126
address1,
126127
address2
127128
}
128129
`)
129130

130-
expect(result.addressDetails).toBeUndefined()
131-
expect(result).toEqual({
132-
address1: data.addressDetails.address1,
133-
address2: data.addressDetails.address2
131+
expect(result.addressDetails).toBeUndefined()
132+
expect(result).toEqual({
133+
address1: data.addressDetails.address1,
134+
address2: data.addressDetails.address2
135+
})
134136
})
135137
})
136-
})
137138

138-
describe('exec', () => {
139-
it('should set node.options.exec to a method in the current depth', () => {
140-
const value = 'test-value'
141-
const arg = 'test-arg'
142-
const args = [
143-
'arg1',
144-
'arg2'
145-
]
146-
const dataWithFn = {
147-
...data,
148-
testFn: jest.fn().mockReturnValue(value)
149-
}
150-
const node = {
151-
options: {
152-
exec: null
153-
}
154-
}
155-
156-
filters.exec({
157-
node,
158-
data: dataWithFn,
159-
flag: null,
160-
args: [
161-
'testFn',
162-
...args
139+
describe('exec', () => {
140+
it('should set node.options.exec to a method in the current depth', () => {
141+
const value = 'test-value'
142+
const arg = 'test-arg'
143+
const args = [
144+
'arg1',
145+
'arg2'
163146
]
164-
})
147+
const dataWithFn = {
148+
...data,
149+
testFn: jest.fn().mockReturnValue(value)
150+
}
151+
const node = {
152+
options: {
153+
exec: null
154+
}
155+
}
165156

166-
const result = node.options.exec(arg)
157+
filters.exec({
158+
node,
159+
data: dataWithFn,
160+
flag: null,
161+
args: [
162+
'testFn',
163+
...args
164+
]
165+
})
167166

168-
expect(dataWithFn.testFn).toBeCalledWith(arg, ...args)
169-
expect(result).toEqual(value)
170-
})
167+
const result = node.options.exec(arg)
168+
169+
expect(dataWithFn.testFn).toBeCalledWith(arg, ...args)
170+
expect(result).toEqual(value)
171+
})
171172

172-
it('should execute a method in the current depth with the picked value', () => {
173-
const value = 'test-value'
174-
const arg = 'foo'
175-
const dataWithFn = {
176-
...data,
177-
testFn: jest
178-
.fn()
179-
.mockReturnValue(value)
180-
}
181-
const result = yank(dataWithFn, `
173+
it('should execute a method in the current depth with the picked value', () => {
174+
const value = 'test-value'
175+
const arg = 'foo'
176+
const dataWithFn = {
177+
...data,
178+
testFn: jest
179+
.fn()
180+
.mockReturnValue(value)
181+
}
182+
const result = yank(dataWithFn, `
182183
firstName | exec(testFn, ${arg})
183184
`)
184185

185-
expect(dataWithFn.testFn).toBeCalledWith(data.firstName, arg)
186-
expect(result).toEqual({
187-
firstName: value
186+
expect(dataWithFn.testFn).toBeCalledWith(data.firstName, arg)
187+
expect(result).toEqual({
188+
firstName: value
189+
})
188190
})
189191
})
190192
})
193+
194+
describe('Filter', () => {
195+
describe('filter', () => {
196+
// @TODO
197+
})
198+
})
191199
})

tests/parser.spec.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,6 @@ describe('src/parser', () => {
5757
})
5858
})
5959

60-
describe('filterfy', () => {
61-
it('should create an array of filters from a given node in a schema', () => {
62-
const raws = ['nullable', 'as(first_name)']
63-
const parser = new Parser([])
64-
const [nullable, as] = parser.filterfy(raws)
65-
66-
expect(nullable).toEqual(expect.objectContaining({
67-
name: 'nullable',
68-
args: []
69-
}))
70-
expect(as).toEqual(expect.objectContaining({
71-
name: 'as',
72-
args: [
73-
'first_name'
74-
]
75-
}))
76-
})
77-
})
78-
7960
describe('tokenise', () => {
8061
const tokenise = tok => {
8162
const parser = new Parser([])
@@ -158,7 +139,7 @@ describe('src/parser', () => {
158139
})
159140

160141
describe('measure', () => {
161-
it.only('should measure the size of scope given', () => {
142+
it('should measure the size of scope given', () => {
162143
const parser = new Parser([])
163144

164145
expect(parser.measure(':{')).toEqual(1)

0 commit comments

Comments
 (0)