mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Improve tests for moveAbove() / moveBelow().
This commit is contained in:
parent
949752556b
commit
092ea182dc
2 changed files with 14 additions and 14 deletions
|
@ -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 /, '')
|
||||||
|
|
|
@ -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]);
|
||||||
|
|
Loading…
Reference in a new issue