From 40832a524b75f03f3c98996e00c946af8447456d Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Sat, 21 May 2011 19:41:02 +0200 Subject: [PATCH] Tests helpers: implement compareSegments and compareSegmentLists. --- test/lib/helpers.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/lib/helpers.js b/test/lib/helpers.js index d3be2b6b..e931d696 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -193,6 +193,44 @@ function compareParagraphStyles(paragraphStyle, paragraphStyle2, checkIdentity) }); } +function compareSegments(segment, segment2, checkIdentity) { + var keys = ['handleIn', 'handleOut', 'point']; + if (checkIdentity) { + equals(function() { + return segment !== segment2; + }, true); + } + + for (var i = 0, l = keys.length; i < l; i++) { + var key = keys[i]; + if (checkIdentity) { + equals(function() { + return segment[key] !== segment2[key]; + }, true, 'Strict compare Segment#' + key); + } + equals(segment[key] && segment[key].toString(), + segment2[key] && segment2[key].toString(), + 'Compare Segment#' + key); + } +} + +function compareSegmentLists(segmentList, segmentList2, checkIdentity) { + if (checkIdentity) { + equals(function() { + return segmentList !== segmentList2; + }, true); + } + equals(segmentList.toString(), segmentList2.toString(), + 'Compare Item#segments'); + if (checkIdentity) { + for (var i = 0, l = segmentList.length; i < l; i++) { + var segment = segmentList[i], + segment2 = segmentList2[i]; + compareSegments(segment, segment2, checkIdentity); + } + } +} + function compareItems(item, item2, checkIdentity) { if (checkIdentity) { equals(function() {