'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

exports.default = validateArguments;

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var optionsValidation = {
  expectedType: 'object or function',
  predicate: function predicate(_ref) {
    var options = _ref.options;

    return _lodash2.default.isPlainObject(options);
  }
};

var optionsTimeoutValidation = {
  identifier: '"options.timeout"',
  expectedType: 'integer',
  predicate: function predicate(_ref2) {
    var options = _ref2.options;

    return !options.timeout || _lodash2.default.isInteger(options.timeout);
  }
};

var fnValidation = {
  expectedType: 'function',
  predicate: function predicate(_ref3) {
    var code = _ref3.code;

    return _lodash2.default.isFunction(code);
  }
};

var validations = {
  defineTestRunHook: [(0, _extends3.default)({ identifier: 'first argument' }, optionsValidation), optionsTimeoutValidation, (0, _extends3.default)({ identifier: 'second argument' }, fnValidation)],
  defineTestCaseHook: [(0, _extends3.default)({ identifier: 'first argument' }, optionsValidation), {
    identifier: '"options.tags"',
    expectedType: 'string',
    predicate: function predicate(_ref4) {
      var options = _ref4.options;

      return !options.tags || _lodash2.default.isString(options.tags);
    }
  }, optionsTimeoutValidation, (0, _extends3.default)({ identifier: 'second argument' }, fnValidation)],
  defineStep: [{
    identifier: 'first argument',
    expectedType: 'string or regular expression',
    predicate: function predicate(_ref5) {
      var pattern = _ref5.pattern;

      return _lodash2.default.isRegExp(pattern) || _lodash2.default.isString(pattern);
    }
  }, (0, _extends3.default)({ identifier: 'second argument' }, optionsValidation), optionsTimeoutValidation, (0, _extends3.default)({ identifier: 'third argument' }, fnValidation)]
};

function validateArguments(_ref6) {
  var args = _ref6.args,
      fnName = _ref6.fnName,
      location = _ref6.location;

  validations[fnName].forEach(function (_ref7) {
    var identifier = _ref7.identifier,
        expectedType = _ref7.expectedType,
        predicate = _ref7.predicate;

    if (!predicate(args)) {
      throw new Error(location + ': Invalid ' + identifier + ': should be a ' + expectedType);
    }
  });
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5064 characters]