From b29827443ecb7283581f296b601ad0a6faafdfe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 26 May 2011 09:20:21 +0100 Subject: [PATCH] Add compareObjects() method for functionality shared among various compare methods. --- test/lib/helpers.js | 50 +++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/test/lib/helpers.js b/test/lib/helpers.js index 822a81fd..62aac57b 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -132,7 +132,7 @@ function comparePathStyles(style, style2, checkIdentity) { }); Base.each(['strokeCap', 'strokeJoin', 'dashOffset', 'miterLimit', - 'strokeOverprint', 'fillOverprint'], function(key) { + 'strokeOverprint', 'fillOverprint'], function(key) { if (style[key]) { equals(function() { return style[key] == style2[key]; @@ -146,52 +146,35 @@ function comparePathStyles(style, style2, checkIdentity) { } } -function compareCharacterStyles(characterStyle, characterStyle2, checkIdentity) { +function compareObjects(name, keys, obj1, obj2, checkIdentity) { if (checkIdentity) { equals(function() { - return characterStyle != characterStyle2; + return obj1 != obj2; }, true); } - var keys = ['fontSize', 'font']; Base.each(keys, function(key) { equals(function() { - return characterStyle[key] == characterStyle2[key]; - }, true, 'Compare CharacterStyle#' + key); + return obj1[key] == obj2[key]; + }, true, 'Compare ' + name + '#' + key); }); +} +function compareCharacterStyles(characterStyle, characterStyle2, checkIdentity) { + compareObjects('CharacterStyle', ['fontSize', 'font'], + characterStyle, characterStyle2, checkIdentity); } function compareParagraphStyles(paragraphStyle, paragraphStyle2, checkIdentity) { - if (checkIdentity) { - equals(function() { - return paragraphStyle != paragraphStyle2; - }, true); - } - var keys = ['justification']; - Base.each(keys, function(key) { - equals(function() { - return style[key] == style2[key]; - }, true, 'Compare ParagraphStyle#' + key); - }); + compareObjects('ParagraphStyle', ['justification'], + paragraphStyle, paragraphStyle2, checkIdentity); } function compareSegmentPoints(segmentPoint, segmentPoint2, checkIdentity) { - if (checkIdentity) { - equals(function() { - return segmentPoint !== segmentPoint2; - }, true); - } - var keys = ['selected', 'x', 'y']; - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i]; - equals(function() { - return segmentPoint[key] == segmentPoint2[key]; - }, true, 'Compare SegmentPoint#' + key); - } + compareObjects('ParagraphStyle', ['x', 'y', 'selected'], + segmentPoint, segmentPoint2, checkIdentity); } function compareSegments(segment, segment2, checkIdentity) { - var keys = ['handleIn', 'handleOut', 'point']; if (checkIdentity) { equals(function() { return segment !== segment2; @@ -200,10 +183,9 @@ function compareSegments(segment, segment2, checkIdentity) { equals(function() { return segment.selected == segment2.selected; }, true); - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i]; + Base.each(['handleIn', 'handleOut', 'point'], function(key) { compareSegmentPoints(segment[key], segment2[key]); - } + }); } function compareSegmentLists(segmentList, segmentList2, checkIdentity) { @@ -357,4 +339,4 @@ function compareItems(item, item2, checkIdentity) { compareItems(item.children[i], item2.children[i], checkIdentity); } } -} \ No newline at end of file +}