text: var test = require('tape')
  var utils = require('./')
  
  test('methods', function (t) {
  
    t.equal(utils.getAlias({value: {alias: 'test'}}), 'test', 'getAlias()')
  
    t.ok(
      utils.valueDoesNotHaveAlias({value: {anything: {}}}),
      'valueDoesNotHaveAlias() missing alias'
    )
    t.notOk(
      utils.valueDoesNotHaveAlias({value: {alias: ['test']}}),
      'valueDoesNotHaveAlias() has alias'
    )
  
    t.ok(
      utils.isCommand({type: 'command'}),
      'isCommand() true'
    )
    t.notOk(
      utils.isCommand({type: 'flag'}),
      'isCommand() false'
    )
  
    t.ok(
      utils.isFlag({type: 'flag'}),
      'isFlag() true'
    )
    t.notOk(
      utils.isFlag({type: 'command'}),
      'isFlag() false'
    )
  
    var data = ['test']
    var def1 = {value: {alias: ['test']}}
    var def2 = {value: {}}
    t.ok(utils.containsAlias(data, def1), 'containsAlias() true')
    t.notOk(utils.containsAlias(data, def2), 'containsAlias() false')
    t.ok(utils.matchAlias(data, def1), 'matchesAlias() containing alias')
    t.ok(utils.matchAlias(data, def2), 'matchesAlias() has no alias')
    t.ok(utils.matchAlias(data)(def2), 'matchesAlias() is curried')
  
    t.end()
  })
  
  test('getter methods', function (t) {
  
    var data = ['test']
    var flags = {t: true}
  
    var executionTree1 = [{
      type: 'command',
      value: {alias: ['test']}
    }]
    var executionTree2 = [{
      type: 'flag',
      value: {alias: ['t']}
    }]
  
    t.deepEqual(
      utils.getCommands(data)(executionTree1),
      [{
        type: 'command',
        value: {
          alias: ['test']
        }
      }],
      'getCommands() has commands'
    )
    t.deepEqual(
      utils.getCommands(data)(executionTree2),
      [],
      'getCommands() no commands'
    )
  
    t.deepEqual(
      utils.getFlags(flags)(executionTree2),
      [{
        type: 'flag',
        value: {alias: ['t']}
      }],
      'getFlags() has flags'
    )
    t.deepEqual(
      utils.getFlags(flags)(executionTree1),
      [],
      'getFlags() no flags'
    )
  
    t.end()
  })
  
  test('applyFunctions()', function (t) {
  
    t.plan(13)
  
    var ranFn2 = false
    var fn1 = function (ctx) {
  
      t.deepEqual(ctx.data, ['test'], 'fn1 data')
      t.deepEqual(ctx.flags, {t: true}, 'fn1 flags')
      t.deepEqual(ctx.options, {key: 'value'}, 'fn1 options')
    }
    var fn2 = function () {ranFn2 = true}
    var fn3 = function (arg1, arg2, ctx) {
  
      t.equal(arg1, 'arg1', 'first of args')
      t.equal(arg2, 'arg2', 'second of args')
      t.deepEqual(ctx.options, {key: 'value'}, 'fn1 options')
    }
    var fn4 = function (arg1, ctx) {
  
      t.equal(arg1, 'test', 'computed argument in handler')
      t.deepEqual(ctx.data, ['test'], 'fn4 data')
    }
  
    var data = ['test']
    var flags = {t: true}
    var context = {
      value: {
        'handler': [fn1, fn2]
      },
      options: {key: 'value'}
    }
    var contextWithArgsAsArray = {
      value: {
        'handler': [fn3]
      },
      args: ['arg1', 'arg2'],
      options: {key: 'value'}
    }
    var contextWithArgsAsFunction = {
      value: {
        'handler': [fn4]
      },
      args: function (data, flags) {
  
        t.deepEqual(data, ['test'], 'passes data to args function')
        t.deepEqual(flags, {t: true}, 'passes flags into args function')
  
        return data[0]
      }
    };
  
    utils.applyFunctions(data, flags, context)
    utils.applyFunctions(data, flags, contextWithArgsAsArray)
    utils.applyFunctions(data, flags, contextWithArgsAsFunction)
  
    t.equal(typeof utils.applyFunctions(data), 'function', 'curried once')
    t.equal(typeof utils.applyFunctions(data)(flags), 'function', 'curried twice')
    t.ok(ranFn2, 'ran fn2')
  })
  