'use strict';
var evaluateTestCase, cases;
function browserRunner(cases) {
var keys, tree;
function buildTree(keys) {
var subTrees;
function firstPart(key) {
return key.split('/')[0];
}
function dropFirst(key) {
return _.drop(key.split('/')).join('/');
}
if (keys[0] == "") {
return null;
}
subTrees = _.groupBy(keys, firstPart);
return _.mapValues(subTrees, function (keys, key) {
keys = _.map(keys, dropFirst);
return buildTree(keys);
});
}
function testCaseName(testCase) {
var source, testCaseCase;
source = testCase.source || '';
testCaseCase = testCase.case || '';
try {
encodeURIComponent(source);
} catch (e) {
source = ''
}
return testCase.key + " - " + source + testCaseCase;
}
function describeTests(tree, path) {
var tests, testDirectory;
tests = _.omit(tree, _.isObject);
_.each(_.keys(tests), function (testPath) {
var testCases = _.omit(cases, function (testCase, key) {
return !_.contains(key, path + "/" + testPath);
})
_.each(testCases, function (testCase) {
it(testCaseName(testCase), function () {
evaluateTestCase(testCase);
});
});
});
testDirectory = _.omit(tree, _.isNull);
_.each(testDirectory, function (subTree, key) {
describe(key, function () {
var newPath = path != "" ? path + "/" + key : key;
describeTests(subTree, newPath)
})
})
}
describeTests(buildTree(_.keys(cases)), '');
}
evaluateTestCase = window.evaluateTestCase;
cases = createTestCases();
browserRunner(cases);