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);
|
||||
});
|
||||
|
||||
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()
|
||||
function equals(actual, expected, message, tolerance) {
|
||||
if (typeof actual === 'function') {
|
||||
if (!message) {
|
||||
message = actual.toString().match(
|
||||
/^\s*function[^\{]*\{([\s\S]*)\}\s*$/)[1]
|
||||
.replace(/ /g, '')
|
||||
.replace(/^\s+|\s+$/g, '');
|
||||
message = getFunctionBody(actual);
|
||||
if (/^return /.test(message)) {
|
||||
message = message
|
||||
.replace(/^return /, '')
|
||||
|
|
|
@ -56,22 +56,18 @@ test('Item Order', function() {
|
|||
|
||||
test('Item#moveAbove(item) / Item#moveBelow(item)', function() {
|
||||
var item0, item1, item2;
|
||||
var testMove = function(command, indexes) {
|
||||
|
||||
function testMove(command, indexes) {
|
||||
paper.project.clear();
|
||||
new Layer();
|
||||
item0 = new Group();
|
||||
item1 = new Group();
|
||||
item2 = new Group();
|
||||
command();
|
||||
equals(function() {
|
||||
return item0.index;
|
||||
}, indexes[0], command.toString());
|
||||
equals(function() {
|
||||
return item1.index;
|
||||
}, indexes[1]);
|
||||
equals(function() {
|
||||
return item2.index;
|
||||
}, indexes[2]);
|
||||
var str = getFunctionBody(command);
|
||||
equals(item0.index, indexes[0], str + ': item0.index');
|
||||
equals(item1.index, indexes[1], str + ': item1.index');
|
||||
equals(item2.index, indexes[2], str + ': item2.index');
|
||||
}
|
||||
|
||||
testMove(function() { item0.moveBelow(item0) }, [0,1,2]);
|
||||
|
|
Loading…
Reference in a new issue