Refactor walker.test to create explicit expected variables
parent
57f5d581e3
commit
a3aa112cc3
|
@ -15,7 +15,7 @@ describe('IFQL.AST.Walker', () => {
|
|||
describe('a single expression', () => {
|
||||
it('returns a flattened ordered list of from and its args', () => {
|
||||
const walker = new Walker(From)
|
||||
expect(walker.body).toEqual([
|
||||
const expectedWalkerBody = [
|
||||
{
|
||||
type: 'CallExpression',
|
||||
source: 'from(db: "telegraf")',
|
||||
|
@ -32,14 +32,15 @@ describe('IFQL.AST.Walker', () => {
|
|||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
]
|
||||
expect(walker.body).toEqual(expectedWalkerBody)
|
||||
})
|
||||
|
||||
describe('variables', () => {
|
||||
describe('a single string literal variable', () => {
|
||||
it('returns the expected list', () => {
|
||||
const walker = new Walker(StringLiteral)
|
||||
expect(walker.body).toEqual([
|
||||
const expectedWalkerBody = [
|
||||
{
|
||||
type: 'VariableDeclaration',
|
||||
source: 'bux = "im a var"',
|
||||
|
@ -51,14 +52,15 @@ describe('IFQL.AST.Walker', () => {
|
|||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
]
|
||||
expect(walker.body).toEqual(expectedWalkerBody)
|
||||
})
|
||||
})
|
||||
|
||||
describe('a single expression variable', () => {
|
||||
it('returns the expected list', () => {
|
||||
const walker = new Walker(Expression)
|
||||
expect(walker.body).toEqual([
|
||||
const expectedWalkerBody = [
|
||||
{
|
||||
type: 'VariableDeclaration',
|
||||
source: 'tele = from(db: "telegraf")',
|
||||
|
@ -82,14 +84,15 @@ describe('IFQL.AST.Walker', () => {
|
|||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
]
|
||||
expect(walker.body).toEqual(expectedWalkerBody)
|
||||
})
|
||||
})
|
||||
|
||||
describe('a single ArrowFunction variable', () => {
|
||||
it('returns the expected list', () => {
|
||||
const walker = new Walker(ArrowFunction)
|
||||
expect(walker.body).toEqual([
|
||||
const expectedWalkerBody = [
|
||||
{
|
||||
type: 'VariableDeclaration',
|
||||
source: 'addOne = (n) => n + 1',
|
||||
|
@ -107,14 +110,15 @@ describe('IFQL.AST.Walker', () => {
|
|||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
]
|
||||
expect(walker.body).toEqual(expectedWalkerBody)
|
||||
})
|
||||
})
|
||||
|
||||
describe('forking', () => {
|
||||
it('return the expected list of objects', () => {
|
||||
const walker = new Walker(Fork)
|
||||
expect(walker.body).toEqual([
|
||||
const expectedWalkerBody = [
|
||||
{
|
||||
type: 'VariableDeclaration',
|
||||
source: 'tele = from(db: "telegraf")',
|
||||
|
@ -146,7 +150,8 @@ describe('IFQL.AST.Walker', () => {
|
|||
{args: [], name: 'sum', source: '|> sum()'},
|
||||
],
|
||||
},
|
||||
])
|
||||
]
|
||||
expect(walker.body).toEqual(expectedWalkerBody)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -156,7 +161,7 @@ describe('IFQL.AST.Walker', () => {
|
|||
describe('Args that are objects', () => {
|
||||
it('returns an object when arg type is object', () => {
|
||||
const walker = new Walker(JoinWithObjectArg)
|
||||
expect(walker.body).toEqual([
|
||||
const expectedWalkerBody = [
|
||||
{
|
||||
type: 'CallExpression',
|
||||
source:
|
||||
|
@ -178,14 +183,15 @@ describe('IFQL.AST.Walker', () => {
|
|||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
]
|
||||
expect(walker.body).toEqual(expectedWalkerBody)
|
||||
})
|
||||
})
|
||||
|
||||
describe('complex example', () => {
|
||||
it('returns a flattened ordered list of all funcs and their args', () => {
|
||||
const walker = new Walker(Complex)
|
||||
expect(walker.body).toEqual([
|
||||
const expectedWalkerBody = [
|
||||
{
|
||||
type: 'PipeExpression',
|
||||
source:
|
||||
|
@ -213,7 +219,8 @@ describe('IFQL.AST.Walker', () => {
|
|||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
]
|
||||
expect(walker.body).toEqual(expectedWalkerBody)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue