mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Some more clean-up in unit test helpers code.
This commit is contained in:
parent
644fb71dc1
commit
5890de3a80
1 changed files with 17 additions and 16 deletions
|
@ -28,9 +28,10 @@ QUnit.jsDump.setParser('object', function (obj, stack) {
|
||||||
});
|
});
|
||||||
|
|
||||||
function compareProperties(actual, expected, properties, message, options) {
|
function compareProperties(actual, expected, properties, message, options) {
|
||||||
Base.each(properties, function(key) {
|
for (var i = 0, l = properties.length; i < l; i++) {
|
||||||
|
var key = properties[i];
|
||||||
equals(actual[key], expected[key], message + '.' + key, options);
|
equals(actual[key], expected[key], message + '.' + key, options);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareItem(actual, expected, message, options, properties) {
|
function compareItem(actual, expected, message, options, properties) {
|
||||||
|
@ -55,6 +56,8 @@ function compareItem(actual, expected, message, options, properties) {
|
||||||
message + '.style', options);
|
message + '.style', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A list of comparator functions, based on `expected` type. See equals() for
|
||||||
|
// an explanation of how the type is determined.
|
||||||
var comparators = {
|
var comparators = {
|
||||||
Null: QUnit.strictEqual,
|
Null: QUnit.strictEqual,
|
||||||
Undefined: QUnit.strictEqual,
|
Undefined: QUnit.strictEqual,
|
||||||
|
@ -121,11 +124,8 @@ var comparators = {
|
||||||
},
|
},
|
||||||
|
|
||||||
Segment: function(actual, expected, message, options) {
|
Segment: function(actual, expected, message, options) {
|
||||||
Base.each(['handleIn', 'handleOut', 'point', 'selected'],
|
compareProperties(actual, expected, ['handleIn', 'handleOut', 'point',
|
||||||
function(key) {
|
'selected'], message, options);
|
||||||
equals(actual[key], expected[key], message + '.' + key);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
SegmentPoint: function(actual, expected, message, options) {
|
SegmentPoint: function(actual, expected, message, options) {
|
||||||
|
@ -137,17 +137,17 @@ var comparators = {
|
||||||
Item: compareItem,
|
Item: compareItem,
|
||||||
|
|
||||||
Group: function(actual, expected, message, options) {
|
Group: function(actual, expected, message, options) {
|
||||||
compareItem(actual, expected, message, options,
|
compareItem(actual, expected, message, options, ['clipped']);
|
||||||
['clipped']);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
Layer: function(actual, expected, message, options) {
|
Layer: function(actual, expected, message, options) {
|
||||||
compareItem(actual, expected, message, options);
|
compareItem(actual, expected, message, options);
|
||||||
equals(function() {
|
var sameProject = actual.project === expected.project;
|
||||||
return options && options.dontShareProject
|
var sharedProject = !(options && options.dontShareProject);
|
||||||
? actual.project !== expected.project
|
QUnit.push(sharedProject ? sameProject : !sameProject,
|
||||||
: actual.project === expected.project;
|
actual.project,
|
||||||
}, true);
|
sharedProject ? expected.project : 'not ' + expected.project,
|
||||||
|
message + '.project');
|
||||||
},
|
},
|
||||||
|
|
||||||
Path: function(actual, expected, message, options) {
|
Path: function(actual, expected, message, options) {
|
||||||
|
@ -191,7 +191,8 @@ var comparators = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var strictIdenticalAfterCloning = {
|
// A list of classes that should be identical after their owners were cloned.
|
||||||
|
var identicalAfterCloning = {
|
||||||
Gradient: true,
|
Gradient: true,
|
||||||
Symbol: true
|
Symbol: true
|
||||||
};
|
};
|
||||||
|
@ -245,7 +246,7 @@ function equals(actual, expected, message, options) {
|
||||||
QUnit.push(actual === expected, actual, expected, message);
|
QUnit.push(actual === expected, actual, expected, message);
|
||||||
}
|
}
|
||||||
if (options && options.cloned && cls) {
|
if (options && options.cloned && cls) {
|
||||||
var identical = strictIdenticalAfterCloning[cls];
|
var identical = identicalAfterCloning[cls];
|
||||||
QUnit.push(identical ? actual === expected : actual !== expected,
|
QUnit.push(identical ? actual === expected : actual !== expected,
|
||||||
actual, identical ? expected : 'not ' + expected,
|
actual, identical ? expected : 'not ' + expected,
|
||||||
message + ': identical after cloning');
|
message + ': identical after cloning');
|
||||||
|
|
Loading…
Reference in a new issue