2010-01-07 20:21:07 +00:00
|
|
|
$(function() {
|
|
|
|
|
2011-02-09 17:56:35 +00:00
|
|
|
var $body = $('body')
|
2010-01-07 20:21:07 +00:00
|
|
|
.css({
|
2011-02-09 17:56:35 +00:00
|
|
|
overflowY: 'auto'
|
2010-01-07 20:21:07 +00:00
|
|
|
}),
|
|
|
|
$tests = new Ox.Bar({
|
|
|
|
size: 20
|
|
|
|
})
|
|
|
|
.css({
|
2011-02-09 17:56:35 +00:00
|
|
|
padding: '6px 0 6px 8px',
|
|
|
|
fontSize: '16px',
|
|
|
|
fontWeight: 'bold'
|
2010-01-07 20:21:07 +00:00
|
|
|
})
|
2011-02-09 17:56:35 +00:00
|
|
|
.appendTo($('body'));
|
2010-01-07 20:21:07 +00:00
|
|
|
colors = [
|
2011-02-09 17:56:35 +00:00
|
|
|
['255, 64, 64', '224, 32, 32', '240, 16, 16'],
|
|
|
|
['64, 192, 64', '32, 160, 32', '40, 176, 48'],
|
|
|
|
['96, 96, 255', '64, 64, 224', '80, 80, 240']
|
2010-01-07 20:21:07 +00:00
|
|
|
],
|
|
|
|
gradients = [
|
2011-02-09 17:56:35 +00:00
|
|
|
'-moz-linear-gradient(',
|
|
|
|
'-webkit-gradient(linear, '
|
2010-01-07 20:21:07 +00:00
|
|
|
];
|
2011-02-09 17:56:35 +00:00
|
|
|
|
2010-01-07 20:21:07 +00:00
|
|
|
setBackground($tests, true);
|
|
|
|
|
2011-02-22 10:02:28 +00:00
|
|
|
tests(['../build/js/ox.js', '../build/js/ox.data.js']);
|
2010-01-07 20:21:07 +00:00
|
|
|
|
|
|
|
function tests() {
|
|
|
|
var succeeded = 0, failed = 0,
|
|
|
|
lines, spaces, command, expected, result, success,
|
2011-02-09 17:56:35 +00:00
|
|
|
replace = ['', ''], fns = [], $test
|
2011-02-22 10:02:28 +00:00
|
|
|
Ox.forEach(Ox.isArray(arguments[0]) ? arguments[0] : arguments, function(script, i) {
|
|
|
|
Ox.print(script, Ox)
|
2010-01-07 20:21:07 +00:00
|
|
|
$.get(script, function(data) {
|
2011-02-22 10:02:28 +00:00
|
|
|
Ox.print(script, Ox)
|
2011-02-09 17:56:35 +00:00
|
|
|
new Ox.Bar({size: 17})
|
|
|
|
.css({padding: '3px 0 0 8px'})
|
2010-01-07 20:21:07 +00:00
|
|
|
.html(Ox.basename(script))
|
|
|
|
.appendTo($body);
|
2011-02-09 17:56:35 +00:00
|
|
|
lines = data.split('\n');
|
2010-01-07 20:21:07 +00:00
|
|
|
$.each(lines, function(l, line) {
|
2011-02-09 17:56:35 +00:00
|
|
|
if (line.indexOf('/*') > -1 && lines[l + 1].indexOf('====') > -1) {
|
|
|
|
new Ox.Bar({size: 17})
|
|
|
|
.css({padding: '3px 0 0 24px'})
|
2010-01-07 20:21:07 +00:00
|
|
|
.html($.trim(lines[l + 2]))
|
|
|
|
.appendTo($body);
|
|
|
|
//setBackground(x, 2)
|
|
|
|
}
|
2011-02-09 17:56:35 +00:00
|
|
|
spaces = line.indexOf('>>> ');
|
2010-01-07 20:21:07 +00:00
|
|
|
if (spaces > -1) {
|
2011-02-09 17:56:35 +00:00
|
|
|
command = $.trim(line).substr(4).split(' // ')[0];
|
2011-02-22 10:02:28 +00:00
|
|
|
fn = command.match(/Ox\.\w+/g);
|
|
|
|
Ox.print('fn', fn)
|
|
|
|
//Ox.print(lines[l + 1].substr(spaces, lines[l + 1].length), eval(lines[l + 1].substr(spaces, lines[l + 1].length)))
|
|
|
|
Ox.print(lines[l + 1].substr(spaces, lines[l + 1].length));
|
2010-01-07 20:21:07 +00:00
|
|
|
expected = eval(lines[l + 1].substr(spaces, lines[l + 1].length));
|
|
|
|
// fixme: if object, recursively check identity
|
|
|
|
result = eval(command);
|
|
|
|
if (fn) {
|
2011-02-22 10:02:28 +00:00
|
|
|
fn = fn[fn.length - 1];
|
|
|
|
/*
|
2011-02-09 17:56:35 +00:00
|
|
|
success = typeof expected == 'object' ?
|
2010-01-07 20:21:07 +00:00
|
|
|
expected.toString() == result.toString() : expected === result;
|
2011-02-22 10:02:28 +00:00
|
|
|
*/
|
|
|
|
Ox.print('command:', command, 'expected:', expected, 'result:', result)
|
|
|
|
success = Ox.isEqual(expected, result);
|
2010-01-07 20:21:07 +00:00
|
|
|
succeeded += success;
|
|
|
|
failed += !success;
|
2011-02-09 17:56:35 +00:00
|
|
|
$tests.html((succeeded + failed) + ' tests, ' +
|
|
|
|
succeeded + ' succeeded, ' + failed + ' failed');
|
2010-01-07 20:21:07 +00:00
|
|
|
if (!success) {
|
|
|
|
setBackground($tests, success);
|
|
|
|
}
|
|
|
|
if ($.inArray(fn, fns) == -1) {
|
|
|
|
fns.push(fn);
|
|
|
|
$test = Ox.CollapsePanel({
|
|
|
|
collapsed: true,
|
2011-02-09 17:56:35 +00:00
|
|
|
title: fn + '()'
|
2010-01-07 20:21:07 +00:00
|
|
|
})
|
|
|
|
.appendTo($body);
|
2011-02-09 17:56:35 +00:00
|
|
|
setBackground($test.find('.OxBar'), true);
|
2010-01-07 20:21:07 +00:00
|
|
|
}
|
|
|
|
///*
|
2011-02-09 17:56:35 +00:00
|
|
|
new Ox.Bar({size:17}) // fixme: Ox.Object() used to work
|
2010-01-07 20:21:07 +00:00
|
|
|
.css({
|
2011-02-09 17:56:35 +00:00
|
|
|
//padding: '2px 0 2px 8px',
|
|
|
|
background: 'rgb(' + colors[+success][2] + ')'
|
2010-01-07 20:21:07 +00:00
|
|
|
})
|
|
|
|
.html(
|
2011-02-09 17:56:35 +00:00
|
|
|
Ox.basename(script) + ', line ' + l + ': <span style="font-weight: bold">' +
|
|
|
|
Ox.encodeHTML(command).replace(replace[0], replace[1]) + ' ' +
|
2011-02-22 10:02:28 +00:00
|
|
|
(success ? '=' : '!') + '=> ' + Ox.encodeHTML(JSON.stringify(expected)) +
|
|
|
|
(success ? '' : ' ==> ' + Ox.encodeHTML(JSON.stringify(result))) + '</span>'
|
2010-01-07 20:21:07 +00:00
|
|
|
)
|
|
|
|
.appendTo($test.$content);
|
|
|
|
//*/
|
|
|
|
// to be fixed in ui:
|
|
|
|
// /*
|
|
|
|
$test.$content
|
|
|
|
.css({
|
2011-02-09 17:56:35 +00:00
|
|
|
marginTop: -$test.$content.height() + 'px'
|
2010-01-07 20:21:07 +00:00
|
|
|
});
|
|
|
|
//*/
|
|
|
|
// /*
|
|
|
|
if (!success) {
|
2011-02-09 17:56:35 +00:00
|
|
|
setBackground($test.find('.OxBar'), success);
|
2010-01-07 20:21:07 +00:00
|
|
|
}
|
|
|
|
//*/
|
|
|
|
} else {
|
2011-02-09 17:56:35 +00:00
|
|
|
replace = command.split(' = ')
|
2010-01-07 20:21:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-02-22 10:02:28 +00:00
|
|
|
}, 'html');
|
2010-01-07 20:21:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setBackground($element, success) {
|
|
|
|
$.each(gradients, function(i, v) {
|
|
|
|
$element.css({
|
2011-02-09 17:56:35 +00:00
|
|
|
background: v + 'left top, left bottom, from(rgb(' +
|
|
|
|
colors[+success][0] + ')), to(rgb(' +
|
|
|
|
colors[+success][1] + ')))'
|
2010-01-07 20:21:07 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|