Improve tests for moveAbove() / moveBelow().

This commit is contained in:
Jürg Lehni 2013-07-21 16:11:09 -07:00
parent 949752556b
commit 092ea182dc
2 changed files with 14 additions and 14 deletions

View file

@ -27,14 +27,18 @@ QUnit.jsDump.setParser('object', function (obj, stack) {
: objectParser).call(this, obj, stack); : objectParser).call(this, obj, stack);
}); });
function getFunctionBody(func) {
return func.toString().match(
/^\s*function[^\{]*\{([\s\S]*)\}\s*$/)[1]
.replace(/ /g, '')
.replace(/^\s+|\s+$/g, '');
}
// Override equals to convert functions to message and execute them as tests() // Override equals to convert functions to message and execute them as tests()
function equals(actual, expected, message, tolerance) { function equals(actual, expected, message, tolerance) {
if (typeof actual === 'function') { if (typeof actual === 'function') {
if (!message) { if (!message) {
message = actual.toString().match( message = getFunctionBody(actual);
/^\s*function[^\{]*\{([\s\S]*)\}\s*$/)[1]
.replace(/ /g, '')
.replace(/^\s+|\s+$/g, '');
if (/^return /.test(message)) { if (/^return /.test(message)) {
message = message message = message
.replace(/^return /, '') .replace(/^return /, '')

View file

@ -56,22 +56,18 @@ test('Item Order', function() {
test('Item#moveAbove(item) / Item#moveBelow(item)', function() { test('Item#moveAbove(item) / Item#moveBelow(item)', function() {
var item0, item1, item2; var item0, item1, item2;
var testMove = function(command, indexes) {
function testMove(command, indexes) {
paper.project.clear(); paper.project.clear();
new Layer(); new Layer();
item0 = new Group(); item0 = new Group();
item1 = new Group(); item1 = new Group();
item2 = new Group(); item2 = new Group();
command(); command();
equals(function() { var str = getFunctionBody(command);
return item0.index; equals(item0.index, indexes[0], str + ': item0.index');
}, indexes[0], command.toString()); equals(item1.index, indexes[1], str + ': item1.index');
equals(function() { equals(item2.index, indexes[2], str + ': item2.index');
return item1.index;
}, indexes[1]);
equals(function() {
return item2.index;
}, indexes[2]);
} }
testMove(function() { item0.moveBelow(item0) }, [0,1,2]); testMove(function() { item0.moveBelow(item0) }, [0,1,2]);