simplify async test syntax, allow for files with ?random suffix

This commit is contained in:
rolux 2012-05-27 18:40:51 +02:00
parent 04e2326808
commit f3b0bb6c86

View file

@ -294,7 +294,7 @@ Ox.doc = (function() {
counter = 0, items = [];
files && files.forEach(function(file) {
Ox.get(file, function(source) {
items = items.concat(parseSource(source, file));
items = items.concat(parseSource(source, file.split('?')[0]));
++counter == files.length && callback(items);
});
});
@ -545,29 +545,37 @@ Ox.minify = function() {
Ox.test <f> Takes JavaScript, runs inline tests, returns results
@*/
Ox.test = function(file, callback) {
var regexp = /(Ox\.test\()/;
if (arguments.length == 2) {
Ox.doc(file, function(items) {
var results = [];
file = file.split('?')[0];
Ox.test.data[file] = {
callback: callback,
done: false,
results: [],
tests: {}
};
Ox.doc(file, function(items) {
var results = [];
items.forEach(function(item) {
var actual, match;
item.tests && item.tests.some(function(test) {
return test.result;
}) && item.tests.forEach(function(test) {
Ox.Log('TEST', test.statement);
actual = eval(test.statement);
match = test.statement.match(/Ox\.test\.async\('([\w\.]+)'/);
if (match) {
Ox.test.data[file].tests[match[1]] = {
var actual, isAsync = regexp.test(test.statement);
if (isAsync) {
Ox.test.data[file].tests[item.name] = {
section: item.section,
statement: test.statement
};
} else {
if (test.result) {
test.statement = test.statement.replace(
regexp, '$1\'' + item.name + '\', '
);
}
if (test.result || test.statement.match(/Ox\.test/)) {
// don't eval script tags without assignment to Ox.test.foo
actual = eval(test.statement);
Ox.Log('TEST', test.statement);
}
if (!isAsync && test.result) {
Ox.test.data[file].results.push({
actual: JSON.stringify(actual),
expected: test.result,
@ -579,7 +587,6 @@ Ox.test = function(file, callback) {
), actual)
});
}
}
});
});
Ox.test.data[file].done = true;
@ -587,27 +594,32 @@ Ox.test = function(file, callback) {
callback(Ox.test.data[file].results);
}
});
};
Ox.test.async = function(name, result) {
var file;
} else {
var name = arguments[0],
result = arguments[1],
expected = arguments[2];
file = null;
Ox.forEach(Ox.test.data, function(v, k) {
if (v.tests[name]) {
file = k;
Ox.Break();
}
});
Ox.print('FILE::', file, name, Ox.test.data)
Ox.test.data[file].results.push({
actual: result,
expected: true,
expected: expected,
name: name,
section: Ox.test.data[file].tests[name].section,
statement: Ox.test.data[file].tests[name].statement,
passed: result
passed: Ox.isEqual(result, expected)
});
delete Ox.test.data[file].tests[name];
Ox.print('????::', file, name, Ox.test.data[file])
if (Ox.test.data[file].done && Ox.isEmpty(Ox.test.data[file].tests)) {
Ox.test.data[file].callback(Ox.test.data[file].results);
}
}
};
Ox.test.data = {};