forked from 0x2620/oxjs
Ox.Dialog rewrite
This commit is contained in:
parent
6e5b515e5f
commit
e063626bdc
10 changed files with 762 additions and 513 deletions
100
tests/tests.js
100
tests/tests.js
|
|
@ -26,8 +26,8 @@ Ox.load('UI', function() {
|
|||
tests(['../build/Ox.js'/*, '../build/js/ox.data.js'*/]);
|
||||
|
||||
function tests() {
|
||||
var succeeded = 0, failed = 0,
|
||||
lines, spaces, command, expected, result, success,
|
||||
var passed = 0, failed = 0,
|
||||
lines, spaces, command, expected, result, passed,
|
||||
replace = ['', ''], fns = [], $test
|
||||
Ox.forEach(Ox.isArray(arguments[0]) ? arguments[0] : arguments, function(script, i) {
|
||||
Ox.test(script, function(results) {
|
||||
|
|
@ -37,7 +37,6 @@ Ox.load('UI', function() {
|
|||
tests[result.section][result.name] = tests[result.section][result.name] || [];
|
||||
tests[result.section][result.name].push(result);
|
||||
});
|
||||
Ox.print('tests', tests)
|
||||
Ox.forEach(tests, function(functions, section) {
|
||||
Ox.Bar({size: 14})
|
||||
.css({padding: '1px 0 1px 4px'})
|
||||
|
|
@ -51,27 +50,27 @@ Ox.load('UI', function() {
|
|||
.appendTo($body);
|
||||
setBackground($test.find('.OxBar'), true);
|
||||
arr.forEach(function(test) {
|
||||
succeeded += test.success;
|
||||
failed += !test.success;
|
||||
passed += test.passed;
|
||||
failed += !test.passed;
|
||||
$tests.html(
|
||||
(succeeded + failed) + ' tests, '
|
||||
+ succeeded + ' succeeded, ' + failed + ' failed'
|
||||
(passed + failed) + ' tests, '
|
||||
+ passed + ' passed, ' + failed + ' failed'
|
||||
);
|
||||
if (!test.success) {
|
||||
if (!test.passed) {
|
||||
setBackground($tests, false);
|
||||
setBackground($test.find('.OxBar'), false);
|
||||
}
|
||||
Ox.Element()
|
||||
.css({
|
||||
padding: '2px 0 2px 4px',
|
||||
background: 'rgb(' + colors[+test.success][2] + ')'
|
||||
background: 'rgb(' + colors[+test.passed][2] + ')'
|
||||
})
|
||||
.html(
|
||||
'<span style="font-family: Monaco">'
|
||||
+ Ox.encodeHTML(test.statement) + ' '
|
||||
+ (test.success ? '=' : '!') + '=> '
|
||||
+ (test.passed ? '=' : '!') + '=> '
|
||||
+ Ox.encodeHTML(test.expected)
|
||||
+ (test.success ? '' : ' ==> ' + Ox.encodeHTML(test.actual))
|
||||
+ (test.passed ? '' : ' ==> ' + Ox.encodeHTML(test.actual))
|
||||
+ '</tt>'
|
||||
)
|
||||
.appendTo($test.$content);
|
||||
|
|
@ -82,88 +81,15 @@ Ox.load('UI', function() {
|
|||
});
|
||||
});
|
||||
})
|
||||
/*
|
||||
$.get(script, function(data) {
|
||||
Ox.print(script, Ox)
|
||||
new Ox.Bar({size: 17})
|
||||
.css({padding: '3px 0 0 8px'})
|
||||
.html(Ox.basename(script))
|
||||
.appendTo($body);
|
||||
lines = data.split('\n');
|
||||
$.each(lines, function(l, line) {
|
||||
if (line.indexOf('/*') > -1 && lines[l + 1].indexOf('====') > -1) {
|
||||
new Ox.Bar({size: 17})
|
||||
.css({padding: '3px 0 0 24px'})
|
||||
.html($.trim(lines[l + 2]))
|
||||
.appendTo($body);
|
||||
//setBackground(x, 2)
|
||||
}
|
||||
spaces = line.indexOf('>>> ');
|
||||
if (spaces > -1) {
|
||||
command = $.trim(line).substr(4).split(' // ')[0];
|
||||
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));
|
||||
expected = eval(lines[l + 1].substr(spaces, lines[l + 1].length));
|
||||
// fixme: if object, recursively check identity
|
||||
result = eval(command);
|
||||
if (fn) {
|
||||
fn = fn[fn.length - 1];
|
||||
success = typeof expected == 'object' ?
|
||||
expected.toString() == result.toString() : expected === result;
|
||||
Ox.print('command:', command, 'expected:', expected, 'result:', result)
|
||||
success = Ox.isEqual(expected, result);
|
||||
succeeded += success;
|
||||
failed += !success;
|
||||
$tests.html((succeeded + failed) + ' tests, ' +
|
||||
succeeded + ' succeeded, ' + failed + ' failed');
|
||||
if (!success) {
|
||||
setBackground($tests, success);
|
||||
}
|
||||
if ($.inArray(fn, fns) == -1) {
|
||||
fns.push(fn);
|
||||
$test = Ox.CollapsePanel({
|
||||
collapsed: true,
|
||||
title: fn + '()'
|
||||
})
|
||||
.appendTo($body);
|
||||
setBackground($test.find('.OxBar'), true);
|
||||
}
|
||||
new Ox.Bar({size:17}) // fixme: Ox.Object() used to work
|
||||
.css({
|
||||
//padding: '2px 0 2px 8px',
|
||||
background: 'rgb(' + colors[+success][2] + ')'
|
||||
})
|
||||
.html(
|
||||
Ox.basename(script) + ', line ' + l + ': <span style="font-weight: bold">' +
|
||||
Ox.encodeHTML(command).replace(replace[0], replace[1]) + ' ' +
|
||||
(success ? '=' : '!') + '=> ' + Ox.encodeHTML(JSON.stringify(expected)) +
|
||||
(success ? '' : ' ==> ' + Ox.encodeHTML(JSON.stringify(result))) + '</span>'
|
||||
)
|
||||
.appendTo($test.$content);
|
||||
$test.$content
|
||||
.css({
|
||||
marginTop: -$test.$content.height() + 'px'
|
||||
});
|
||||
} else {
|
||||
replace = command.split(' = ')
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 'html');
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
//});
|
||||
|
||||
function setBackground($element, success) {
|
||||
function setBackground($element, passed) {
|
||||
['-moz-linear-gradient', '-webkit-linear-gradient'].forEach(function(v) {
|
||||
$element.css({
|
||||
background: v + '(top, rgb(' +
|
||||
colors[+success][0] + '), rgb(' +
|
||||
colors[+success][1] + '))'
|
||||
colors[+passed][0] + '), rgb(' +
|
||||
colors[+passed][1] + '))'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue