mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Tests: add checkIdentity flag to helper functions for strict comparison check.
This commit is contained in:
parent
cadace42ce
commit
2bc1c4682d
1 changed files with 24 additions and 11 deletions
|
@ -111,7 +111,7 @@ function cloneAndCompare(item) {
|
||||||
return copy.parent.children[copy.name] == copy;
|
return copy.parent.children[copy.name] == copy;
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
compareItems(item, copy);
|
compareItems(item, copy, true);
|
||||||
// Remove the cloned item to restore the document:
|
// Remove the cloned item to restore the document:
|
||||||
copy.remove();
|
copy.remove();
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,12 @@ function comparePathStyles(style, style2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareCharacterStyles(characterStyle, characterStyle2) {
|
function compareCharacterStyles(characterStyle, characterStyle2, checkIdentity) {
|
||||||
|
if (checkIdentity) {
|
||||||
|
equals(function() {
|
||||||
|
return characterStyle != characterStyle2;
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
var keys = ['fontSize', 'font'];
|
var keys = ['fontSize', 'font'];
|
||||||
Base.each(keys, function(key) {
|
Base.each(keys, function(key) {
|
||||||
equals(function() {
|
equals(function() {
|
||||||
|
@ -160,7 +165,12 @@ function compareCharacterStyles(characterStyle, characterStyle2) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareParagraphStyles(paragraphStyle, paragraphStyle2) {
|
function compareParagraphStyles(paragraphStyle, paragraphStyle2, checkIdentity) {
|
||||||
|
if (checkIdentity) {
|
||||||
|
equals(function() {
|
||||||
|
return paragraphStyle != paragraphStyle2;
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
var keys = ['justification'];
|
var keys = ['justification'];
|
||||||
Base.each(keys, function(key) {
|
Base.each(keys, function(key) {
|
||||||
equals(function() {
|
equals(function() {
|
||||||
|
@ -169,10 +179,12 @@ function compareParagraphStyles(paragraphStyle, paragraphStyle2) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareItems(item, item2) {
|
function compareItems(item, item2, checkIdentity) {
|
||||||
equals(function() {
|
if (checkIdentity) {
|
||||||
return item != item2;
|
equals(function() {
|
||||||
}, true);
|
return item != item2;
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return item.constructor == item2.constructor;
|
return item.constructor == item2.constructor;
|
||||||
|
@ -254,17 +266,18 @@ function compareItems(item, item2) {
|
||||||
// TextItem specific:
|
// TextItem specific:
|
||||||
if (item instanceof TextItem) {
|
if (item instanceof TextItem) {
|
||||||
equals(item.content, item2.content, 'Compare Item#content');
|
equals(item.content, item2.content, 'Compare Item#content');
|
||||||
compareCharacterStyles(item.characterStyle, item2.characterStyle);
|
compareCharacterStyles(item.characterStyle, item2.characterStyle,
|
||||||
|
checkIdentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PointText specific:
|
// PointText specific:
|
||||||
if (item instanceof PointText) {
|
if (item instanceof PointText) {
|
||||||
equals(item.point.toString(), item2.point.toString());
|
equals(item.point.toString(), item2.point.toString(), checkIdentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.style) {
|
if (item.style) {
|
||||||
// Path Style
|
// Path Style
|
||||||
comparePathStyles(item.style, item2.style);
|
comparePathStyles(item.style, item2.style, checkIdentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check length of children and recursively compare them:
|
// Check length of children and recursively compare them:
|
||||||
|
@ -273,7 +286,7 @@ function compareItems(item, item2) {
|
||||||
return item.children.length == item2.children.length;
|
return item.children.length == item2.children.length;
|
||||||
}, true);
|
}, true);
|
||||||
for (var i = 0, l = item.children.length; i < l; i++) {
|
for (var i = 0, l = item.children.length; i < l; i++) {
|
||||||
compareItems(item.children[i], item2.children[i]);
|
compareItems(item.children[i], item2.children[i], checkIdentity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue