oxjs/tests/tests.js

98 lines
3.9 KiB
JavaScript
Raw Normal View History

2011-04-25 14:14:03 +02:00
Ox.load('UI', function() {
2011-04-23 02:20:24 +02:00
//Ox.UI.ready(function() {
2010-01-07 21:21:07 +01:00
2011-02-09 17:56:35 +00:00
var $body = $('body')
2010-01-07 21:21:07 +01:00
.css({
2011-02-09 17:56:35 +00:00
overflowY: 'auto'
2010-01-07 21:21:07 +01: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 21:21:07 +01:00
})
2011-08-12 23:00:42 +02:00
.appendTo($body);
2010-01-07 21:21:07 +01: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 21:21:07 +01:00
];
2011-02-09 17:56:35 +00:00
2010-01-07 21:21:07 +01:00
setBackground($tests, true);
2011-08-12 23:00:42 +02:00
tests(['../build/Ox.js'/*, '../build/js/ox.data.js'*/]);
2010-01-07 21:21:07 +01:00
function tests() {
2011-08-15 14:18:14 +02:00
var passed = 0, failed = 0,
lines, spaces, command, expected, result, passed,
2011-02-09 17:56:35 +00:00
replace = ['', ''], fns = [], $test
2011-02-22 11:02:28 +01:00
Ox.forEach(Ox.isArray(arguments[0]) ? arguments[0] : arguments, function(script, i) {
2011-08-12 23:00:42 +02:00
Ox.test(script, function(results) {
var tests = {};
results.forEach(function(result) {
tests[result.section] = tests[result.section] || {};
tests[result.section][result.name] = tests[result.section][result.name] || [];
tests[result.section][result.name].push(result);
});
Ox.forEach(tests, function(functions, section) {
Ox.Bar({size: 14})
.css({padding: '1px 0 1px 4px'})
.html(Ox.basename(script) + ' ' + section)
.appendTo($body);
Ox.forEach(functions, function(arr, fn) {
var $test = Ox.CollapsePanel({
collapsed: true,
title: fn + '()'
})
.appendTo($body);
setBackground($test.find('.OxBar'), true);
arr.forEach(function(test) {
2011-08-15 14:18:14 +02:00
passed += test.passed;
failed += !test.passed;
2011-08-12 23:00:42 +02:00
$tests.html(
2011-08-15 14:18:14 +02:00
(passed + failed) + ' tests, '
+ passed + ' passed, ' + failed + ' failed'
2011-08-12 23:00:42 +02:00
);
2011-08-15 14:18:14 +02:00
if (!test.passed) {
2011-08-12 23:00:42 +02:00
setBackground($tests, false);
setBackground($test.find('.OxBar'), false);
}
Ox.Element()
.css({
padding: '2px 0 2px 4px',
2011-08-15 14:18:14 +02:00
background: 'rgb(' + colors[+test.passed][2] + ')'
2011-08-12 23:00:42 +02:00
})
.html(
'<span style="font-family: Monaco">'
+ Ox.encodeHTML(test.statement) + ' '
2011-08-15 14:18:14 +02:00
+ (test.passed ? '=' : '!') + '=&gt; '
2011-08-12 23:00:42 +02:00
+ Ox.encodeHTML(test.expected)
2011-08-15 14:18:14 +02:00
+ (test.passed ? '' : ' ==&gt; ' + Ox.encodeHTML(test.actual))
2011-08-12 23:00:42 +02:00
+ '</tt>'
)
.appendTo($test.$content);
});
$test.$content.css({
marginTop: -$test.$content.height() + 'px'
});
});
});
})
2010-01-07 21:21:07 +01:00
});
}
2011-08-15 14:18:14 +02:00
function setBackground($element, passed) {
2011-08-12 23:00:42 +02:00
['-moz-linear-gradient', '-webkit-linear-gradient'].forEach(function(v) {
2010-01-07 21:21:07 +01:00
$element.css({
2011-08-12 23:00:42 +02:00
background: v + '(top, rgb(' +
2011-08-15 14:18:14 +02:00
colors[+passed][0] + '), rgb(' +
colors[+passed][1] + '))'
2010-01-07 21:21:07 +01:00
});
});
}
2011-04-25 14:14:03 +02:00
});