jaune-util
Version:
utils for jaune system
283 lines (154 loc) • 8.33 kB
text/coffeescript
{compileExpression} = require('../../').Reflection
{equal} = require 'assert'
describe 'compileExpression', ->
describe 'without tokens', ->
describe 'with 1 step', ->
before -> = compileExpression 'foo'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 1', -> equal 1, .length
it 'has correct type', -> equal 'n', [0].operation
it 'has correct params', -> equal 'foo', [0].params
describe 'with 2 steps', ->
before -> = compileExpression 'foo.bar'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type on nodes', ->
equal 'n', [0].operation
equal 'n', [1].operation
it 'has correct params', ->
equal 'foo', [0].params
equal 'bar', [1].params
describe 'require token', ->
describe 'basic use', ->
before -> = compileExpression '[r(assert)]'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 1', -> equal 1, .length
it 'has correct type', -> equal 'r', [0].operation
it 'has correct params', -> equal 'assert', [0].params
describe 'with slash', ->
before -> = compileExpression '[r(/node_modules/assert)]'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 1', -> equal 1, .length
it 'has correct type', -> equal 'r', [0].operation
it 'has correct params', -> equal '/node_modules/assert', [0].params
describe 'module token', ->
before -> = compileExpression '[m(assert)]'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 1', -> equal 1, .length
it 'has correct type', -> equal 'm', [0].operation
it 'has correct params', -> equal 'assert', [0].params
describe 'call token', ->
describe 'no params', ->
before -> = compileExpression 'func.[c()]'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type for first node', -> equal 'n', [0].operation
it 'has correct params', -> equal 'func', [0].params
it 'has correct type for second node', -> equal 'c', [1].operation
it 'has no params', -> equal 0, [1].params.length
describe 'with 1 param non-global', ->
before -> = compileExpression 'func.[c(p1)]', p1: 'param 1'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type for first node', -> equal 'n', [0].operation
it 'has correct params', -> equal 'func', [0].params
it 'has correct type for second node', -> equal 'c', [1].operation
it 'has 1 param', -> equal 1, [1].params.length
it 'first parameter value is "param 1"', ->
equal 'param 1', [1].params[0]
describe 'with 3 params non-global', ->
before -> = compileExpression(
'func.[c(p1,p2,p1)]', p1: 'param 1', p2: 'param 2')
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type for first node', -> equal 'n', [0].operation
it 'has correct params', -> equal 'func', [0].params
it 'has correct type for second node', -> equal 'c', [1].operation
it 'has 3 params', -> equal 3, [1].params.length
it 'first parameter value is "param 1"', ->
equal 'param 1', [1].params[0]
it 'second parameter value is "param 2"', ->
equal 'param 2', [1].params[1]
it 'third parameter value is "param 1"', ->
equal 'param 1', [1].params[2]
describe 'with 4: 3 params non-global and 1 global', ->
before -> = compileExpression 'func.[c(p1,p2,p1,p3)]', {
p1: 'param 1', p2: 'param 2', p3: '[g(pg)]'}, {pg: 'param g'}
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type for first node', -> equal 'n', [0].operation
it 'has correct params', -> equal 'func', [0].params
it 'has correct type for second node', -> equal 'c', [1].operation
it 'has 4 params', -> equal 4, [1].params.length
it 'first parameter value is "param 1"', ->
equal 'param 1', [1].params[0]
it 'second parameter value is "param 2"', ->
equal 'param 2', [1].params[1]
it 'third parameter value is "param 1"', ->
equal 'param 1', [1].params[2]
it 'fourth parameter value is "param g"', ->
equal 'param g', [1].params[3]
describe 'instance token', ->
describe 'no params', ->
before -> = compileExpression 'func.[i()]'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type for first node', -> equal 'n', [0].operation
it 'has correct params', -> equal 'func', [0].params
it 'has correct type for second node', -> equal 'i', [1].operation
it 'has no params', -> equal 0, [1].params.length
describe 'with 1 param non-global', ->
before -> = compileExpression 'func.[i(p1)]', p1: 'param 1'
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type for first node', -> equal 'n', [0].operation
it 'has correct params', -> equal 'func', [0].params
it 'has correct type for second node', -> equal 'i', [1].operation
it 'has 1 param', -> equal 1, [1].params.length
it 'first parameter value is "param 1"', ->
equal 'param 1', [1].params[0]
describe 'with 3 params non-global', ->
before -> = compileExpression(
'func.[i(p1,p2,p1)]', p1: 'param 1', p2: 'param 2')
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type for first node', -> equal 'n', [0].operation
it 'has correct params', -> equal 'func', [0].params
it 'has correct type for second node', -> equal 'i', [1].operation
it 'has 3 params', -> equal 3, [1].params.length
it 'first parameter value is "param 1"', ->
equal 'param 1', [1].params[0]
it 'second parameter value is "param 2"', ->
equal 'param 2', [1].params[1]
it 'third parameter value is "param 1"', ->
equal 'param 1', [1].params[2]
describe 'with 4: 3 params non-global and 1 global', ->
before -> = compileExpression 'func.[i(p1,p2,p1,p3)]', {
p1: 'param 1', p2: 'param 2', p3: '[g(pg)]'}, {pg: 'param g'}
after -> = null
it 'returns an array of nodes', -> equal 'object', typeof
it 'has length of 2', -> equal 2, .length
it 'has correct type for first node', -> equal 'n', [0].operation
it 'has correct params', -> equal 'func', [0].params
it 'has correct type for second node', -> equal 'i', [1].operation
it 'has 4 params', -> equal 4, [1].params.length
it 'first parameter value is "param 1"', ->
equal 'param 1', [1].params[0]
it 'second parameter value is "param 2"', ->
equal 'param 2', [1].params[1]
it 'third parameter value is "param 1"', ->
equal 'param 1', [1].params[2]
it 'fourth parameter value is "param g"', ->
equal 'param g', [1].params[3]