'use strict';
(function (root, factory) {
if (typeof module === 'object' && module.exports) {
module.exports = factory(
require('lodash'),
require('../dist/fixtures_js'),
require('../dist/fixtures_json')
);
} else {
root.createTestCases = factory(_, window.fixtures_js, window.fixtures_json);
}
}(this, function (_, jsFixtures, jsonFixtures) {
var cases;
function addCase(key, kind, item) {
if (!cases[key]) {
cases[key] = { key: key };
}
cases[key][kind] = item;
}
function addJsonFixture(value, filePath) {
function getType() {
return _(['tree', 'tokens', 'failure']).find(function (type) {
var suffix = '.' + type;
return (filePath.slice(-suffix.length) === suffix);
});
}
function getKey() {
return filePath.slice(0, -getType().length - 1)
}
function getValue() {
return value;
}
return addCase(getKey(), getType(), getValue());
}
function addJSFixture(value, filePath) {
function checkType(type) {
var suffix = '.' + type;
return filePath.slice(-suffix.length) === suffix
}
function getKey(type) {
return filePath.slice(0, -type.length - 1)
}
function getValue(value, shouldEval) {
var source, newValue;
if (shouldEval) {
newValue = eval(value + ';source');
} else {
newValue = value;
}
return newValue;
}
if (checkType('run')) {
return addCase(getKey('run'), 'run', getValue(value));
}
if (checkType('source')) {
return addCase(getKey('source'), 'source', getValue(value, true));
}
return addCase(filePath, 'case', getValue(value));
}
return function () {
cases = {};
_.each(jsFixtures, addJSFixture);
_.each(jsonFixtures, addJsonFixture);
return cases;
}
}));