Refactor walker.test to create explicit expected variables

ifql/join
ebb-tide 2018-05-30 18:14:54 -07:00
parent 46c30ed92f
commit 94b8501ef9
1 changed files with 21 additions and 14 deletions

View File

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