diff --git a/src/document/Document.js b/src/document/Document.js index a9350e4d..edb3732d 100644 --- a/src/document/Document.js +++ b/src/document/Document.js @@ -55,6 +55,7 @@ var Document = this.Document = Base.extend({ this.bounds = Rectangle.create(0, 0, this._size.width, this._size.height); this.context = this.canvas.getContext('2d'); + // Push it onto paper.documents and adjust index in one: Base.splice(paper.documents, [this]); this.activate(); this.layers = []; diff --git a/src/document/Symbol.js b/src/document/Symbol.js index 3b8766c6..0c735580 100644 --- a/src/document/Symbol.js +++ b/src/document/Symbol.js @@ -29,8 +29,8 @@ var Symbol = this.Symbol = Base.extend({ setDefinition: function(item) { this._definition = item; - this._definition._removeFromParent(); - this._definition.setPosition(new Point(0, 0)); + item._removeFromParent(); + item.setPosition(new Point()); } // TODO: diff --git a/src/item/ChangeFlags.js b/src/item/ChangeFlags.js index 301868b6..943351e3 100644 --- a/src/item/ChangeFlags.js +++ b/src/item/ChangeFlags.js @@ -17,5 +17,6 @@ var ChangeFlags = { PATH: 1, // Path geometry STROKE: 2, // Stroke geometry - STYLE: 4 // Fille style or stroke color / dash -}; \ No newline at end of file + STYLE: 4, // Fille style or stroke color / dash, + HIERARCHY: 8 // Change in item hierarchy +}; diff --git a/src/item/Layer.js b/src/item/Layer.js index 3172db33..faaa7a52 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -20,34 +20,28 @@ var Layer = this.Layer = Group.extend({ initialize: function() { this.children = []; this._document = paper.document; - this._document.layers.push(this); + // Push it onto document.layers and adjust index in one: + Base.splice(this._document.layers, [this]); this.activate(); }, - getIndex: function() { - return this.parent ? this.base() : this._document.layers.indexOf(this); - }, - /** * Removes the layer from its document's layers list * or its parent's children list. */ _removeFromParent: function() { - if (!this.parent) { - return !!this._document.layers.splice(this.getIndex(), 1).length; - } else { - return this.base(); - } + return this.parent ? this.base() + : !!Base.splice(this._document.layers, null, this._index, 1).length; }, getNextSibling: function() { return this.parent ? this.base() - : this._document.layers[this.getIndex() + 1] || null; + : this._document.layers[this._index + 1] || null; }, getPreviousSibling: function() { return this.parent ? this.base() - : this._document.layers[this.getIndex() - 1] || null; + : this._document.layers[this._index - 1] || null; }, activate: function() { @@ -58,14 +52,13 @@ var Layer = this.Layer = Group.extend({ return function(item) { // if the item is a layer and contained within Document#layers if (item instanceof Layer && !item.parent - && this._removeFromParent()) { - item._document.layers.splice(item.getIndex() + (above ? 1 : -1), - 0, this); + && this._removeFromParent()) { + Base.splice(item._document.layers, [this], + item._index + (above ? 1 : -1), 0); this._setDocument(item._document); return true; - } else { - return this.base(item); } + return this.base(item); }; } diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index 2d87ed58..4924812c 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -46,12 +46,6 @@ var CompoundPath = this.CompoundPath = PathItem.extend({ this.children[i].smooth(); }, - moveTo: function() { - var path = new Path(); - this.appendTop(path); - path.moveTo.apply(path, arguments); - }, - draw: function(ctx, param) { var firstChild = this.children[0]; ctx.beginPath(); @@ -70,8 +64,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({ ctx.stroke(); } } -}, new function() { - +}, new function() { // Injection scope for PostScript-like drawing functions function getCurrentPath(that) { if (that.children.length) { return that.children[that.children.length - 1]; @@ -81,6 +74,12 @@ var CompoundPath = this.CompoundPath = PathItem.extend({ } var fields = { + moveTo: function() { + var path = new Path(); + this.appendTop(path); + path.moveTo.apply(path, arguments); + }, + moveBy: function() { var point = arguments.length ? Point.read(arguments) : new Point(), path = getCurrentPath(this), @@ -93,6 +92,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({ } }; + // Redirect all other drawing commands to the current path Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', 'arcTo', 'lineBy', 'curveBy', 'arcBy'], function(key) { fields[key] = function() { diff --git a/src/path/PathItem.js b/src/path/PathItem.js index ea9f76df..62b9aedf 100644 --- a/src/path/PathItem.js +++ b/src/path/PathItem.js @@ -15,7 +15,4 @@ */ var PathItem = this.PathItem = Item.extend({ - initialize: function() { - this.base(); - } }); diff --git a/test/lib/helpers.js b/test/lib/helpers.js index a2ed6cff..36447c3a 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -1,5 +1,22 @@ // Let's be strict -equals = strictEqual; + +function equals(actual, expected, message) { + if (typeof actual === 'function') { + if (!message) { + message = actual.toString().match( + /^\s*function[^\{]*\{([\s\S]*)\}\s*$/)[1] + .replace(/ /g, '') + .replace(/^\s+|\s+$/g, ''); + if (/^return /.test(message)) { + message = message + .replace(/^return /, '') + .replace(/;$/, ''); + } + } + actual = actual(); + } + return strictEqual(actual, expected, message); +} function compareNumbers(number1, number2, message) { if (number1 !== 0) diff --git a/test/tests/CompoundPath.js b/test/tests/CompoundPath.js index cd3c92a1..8d6c054d 100644 --- a/test/tests/CompoundPath.js +++ b/test/tests/CompoundPath.js @@ -18,5 +18,7 @@ test('moveTo / lineTo', function() { path.fillColor = 'black'; - equals(path.children.length, 2); + equals(function() { + return path.children.length; + }, 2)); }); \ No newline at end of file diff --git a/test/tests/Document.js b/test/tests/Document.js index 4a674e3d..ec3d4b32 100644 --- a/test/tests/Document.js +++ b/test/tests/Document.js @@ -5,6 +5,10 @@ test('activate()', function() { var secondDoc = new Document(); doc.activate(); var path = new Path(); - equals(doc.activeLayer.children[0] == path, true); - equals(secondDoc.activeLayer.children.length == 0, true); + equals(function() { + return doc.activeLayer.children[0] == path; + }, true); + equals(function() { + return secondDoc.activeLayer.children.length == 0; + }, true); }); \ No newline at end of file diff --git a/test/tests/Group.js b/test/tests/Group.js index 261d5510..30713029 100644 --- a/test/tests/Group.js +++ b/test/tests/Group.js @@ -3,15 +3,21 @@ module('Group'); test('new Group()', function() { var doc = new Document(); var group = new Group(); - equals(doc.activeLayer.children[0] == group, true); + equals(function() { + return doc.activeLayer.children[0] == group; + }, true); }); test('new Group([item])', function() { var doc = new Document(); var path = new Path(); var group = new Group([path]); - equals(doc.activeLayer.children.length == 1, true); - equals(group.children[0] == path, true); + equals(function() { + return doc.activeLayer.children.length == 1; + }, true); + equals(function() { + return group.children[0] == path; + }, true); }); test('Group bounds', function() { diff --git a/test/tests/Item.js b/test/tests/Item.js index f7191e4f..0bf2cf39 100644 --- a/test/tests/Item.js +++ b/test/tests/Item.js @@ -5,9 +5,15 @@ test('copyTo(document)', function() { var path = new Path(); var secondDoc = new Document(); var copy = path.copyTo(secondDoc); - equals(secondDoc.activeLayer.children.indexOf(copy) != -1, true); - equals(doc.activeLayer.children.indexOf(copy) == -1, true); - equals(copy != path, true); + equals(function() { + return secondDoc.activeLayer.children.indexOf(copy) != -1; + }, true); + equals(function() { + return doc.activeLayer.children.indexOf(copy) == -1; + }, true); + equals(function() { + return copy != path; + }, true); }); test('copyTo(layer)', function() { @@ -16,23 +22,33 @@ test('copyTo(layer)', function() { var layer = new Layer(); var copy = path.copyTo(layer); - equals(layer.children.indexOf(copy) != -1, true); - equals(doc.layers[0].children.indexOf(copy) == -1, true); + equals(function() { + return layer.children.indexOf(copy) != -1; + }, true); + equals(function() { + return doc.layers[0].children.indexOf(copy) == -1; + }, true); }); test('clone()', function() { var doc = new Document(); var path = new Path(); var copy = path.clone(); - equals(doc.activeLayer.children.length == 2, true); - equals(path != copy, true); + equals(function() { + return doc.activeLayer.children.length == 2; + }, true); + equals(function() { + return path != copy; + }, true); }); test('appendChild(item)', function() { var doc = new Document(); var path = new Path(); doc.activeLayer.appendChild(path); - equals(doc.activeLayer.children.length, 1); + equals(function() { + return doc.activeLayer.children.length; + }, 1); }); test('item.parent / item.isChild / item.isParent', function() { @@ -40,23 +56,40 @@ test('item.parent / item.isChild / item.isParent', function() { var secondDoc = new Document(); var path = new Path(); doc.activeLayer.appendChild(path); - equals(doc.activeLayer.children.indexOf(path) != -1, true); + equals(function() { + return doc.activeLayer.children.indexOf(path) != -1; + }, true); secondDoc.activeLayer.appendTop(path); - equals(doc.activeLayer.isChild(path), false); - equals(path.isParent(doc.activeLayer), false); - equals(secondDoc.activeLayer.isChild(path), true); - equals(path.isParent(secondDoc.activeLayer), true); - - equals(doc.activeLayer.children.indexOf(path) == -1, true); - equals(secondDoc.activeLayer.children.indexOf(path) == 0, true); + equals(function() { + return doc.activeLayer.isChild(path); + }, false); + equals(function() { + return path.isParent(doc.activeLayer); + }, false); + equals(function() { + return secondDoc.activeLayer.isChild(path); + }, true); + equals(function() { + return path.isParent(secondDoc.activeLayer); + }, true); + equals(function() { + return doc.activeLayer.children.indexOf(path) == -1; + }, true); + equals(function() { + return secondDoc.activeLayer.children.indexOf(path) == 0; + }, true); }); test('item.lastChild / item.firstChild', function() { var doc = new Document(); var path = new Path(); var secondPath = new Path(); - equals(doc.activeLayer.firstChild == path, true); - equals(doc.activeLayer.lastChild == secondPath, true); + equals(function() { + return doc.activeLayer.firstChild == path; + }, true); + equals(function() { + return doc.activeLayer.lastChild == secondPath; + }, true); }); test('appendBottom(item)', function() { @@ -64,7 +97,9 @@ test('appendBottom(item)', function() { var path = new Path(); var secondPath = new Path(); doc.activeLayer.appendBottom(secondPath); - equals(secondPath.index < path.index, true); + equals(function() { + return secondPath.index < path.index; + }, true); }); test('moveAbove(item)', function() { @@ -72,32 +107,48 @@ test('moveAbove(item)', function() { var path = new Path(); var secondPath = new Path(); path.moveAbove(secondPath); - equals(doc.activeLayer.lastChild == path, true); + equals(function() { + return doc.activeLayer.lastChild == path; + }, true); }); test('moveBelow(item)', function() { var doc = new Document(); var firstPath = new Path(); var secondPath = new Path(); - equals(secondPath.index > firstPath.index, true); + equals(function() { + return secondPath.index > firstPath.index; + }, true); secondPath.moveBelow(firstPath); - equals(secondPath.index < firstPath.index, true); + equals(function() { + return secondPath.index < firstPath.index; + }, true); }); test('isDescendant(item) / isAncestor(item)', function() { var doc = new Document(); var path = new Path(); - equals(path.isDescendant(doc.activeLayer), true); - equals(doc.activeLayer.isDescendant(path), false); - - equals(path.isAncestor(doc.activeLayer), false); - equals(doc.activeLayer.isAncestor(path), true); + equals(function() { + return path.isDescendant(doc.activeLayer); + }, true); + equals(function() { + return doc.activeLayer.isDescendant(path); + }, false); + equals(function() { + return path.isAncestor(doc.activeLayer); + }, false); + equals(function() { + return doc.activeLayer.isAncestor(path); + }, true); // an item can't be its own descendant: - equals(doc.activeLayer.isDescendant(doc.activeLayer), false); - + equals(function() { + return doc.activeLayer.isDescendant(doc.activeLayer); + }, false); // an item can't be its own ancestor: - equals(doc.activeLayer.isAncestor(doc.activeLayer), false); + equals(function() { + return doc.activeLayer.isAncestor(doc.activeLayer); + }, false); }); test('isGroupedWith', function() { @@ -107,34 +158,60 @@ test('isGroupedWith', function() { var group = new Group([path]); var secondGroup = new Group([secondPath]); - equals(path.isGroupedWith(secondPath), false); + equals(function() { + return path.isGroupedWith(secondPath); + }, false); secondGroup.appendTop(path); - equals(path.isGroupedWith(secondPath), true); - equals(path.isGroupedWith(group), false); - equals(path.isDescendant(secondGroup), true); - equals(secondGroup.isDescendant(path), false); - equals(secondGroup.isDescendant(secondGroup), false); - equals(path.isGroupedWith(secondGroup), false); + equals(function() { + return path.isGroupedWith(secondPath); + }, true); + equals(function() { + return path.isGroupedWith(group); + }, false); + equals(function() { + return path.isDescendant(secondGroup); + }, true); + equals(function() { + return secondGroup.isDescendant(path); + }, false); + equals(function() { + return secondGroup.isDescendant(secondGroup); + }, false); + equals(function() { + return path.isGroupedWith(secondGroup); + }, false); paper.document.activeLayer.appendTop(path); - equals(path.isGroupedWith(secondPath), false); + equals(function() { + return path.isGroupedWith(secondPath); + }, false); paper.document.activeLayer.appendTop(secondPath); - equals(path.isGroupedWith(secondPath), false); + equals(function() { + return path.isGroupedWith(secondPath); + }, false); }); test('getPreviousSibling() / getNextSibling()', function() { var doc = new Document(); var firstPath = new Path(); var secondPath = new Path(); - equals(firstPath.nextSibling == secondPath, true); - equals(secondPath.previousSibling == firstPath, true); - equals(secondPath.nextSibling == null, true); + equals(function() { + return firstPath.nextSibling == secondPath; + }, true); + equals(function() { + return secondPath.previousSibling == firstPath; + }, true); + equals(function() { + return secondPath.nextSibling == null; + }, true); }); test('hidden', function() { var doc = new Document(); var firstPath = new Path(); firstPath.visible = false; - equals(firstPath.hidden, true); + equals(function() { + return firstPath.hidden; + }, true); }); test('reverseChildren()', function() { @@ -142,11 +219,19 @@ test('reverseChildren()', function() { var path = new Path(); var secondPath = new Path(); var thirdPath = new Path(); - equals(doc.activeLayer.firstChild == path, true); + equals(function() { + return doc.activeLayer.firstChild == path; + }, true); doc.activeLayer.reverseChildren(); - equals(doc.activeLayer.firstChild == path, false); - equals(doc.activeLayer.firstChild == thirdPath, true); - equals(doc.activeLayer.lastChild == path, true); + equals(function() { + return doc.activeLayer.firstChild == path; + }, false); + equals(function() { + return doc.activeLayer.firstChild == thirdPath; + }, true); + equals(function() { + return doc.activeLayer.lastChild == path; + }, true); }); test('Check item#document when moving items across documents', function() { @@ -155,13 +240,19 @@ test('Check item#document when moving items across documents', function() { var group = new Group(); group.appendTop(new Path()); - equals(path.document == doc1, true); + equals(function() { + return path.document == doc1; + }, true); var doc2 = new Document(); doc2.activeLayer.appendTop(path); - equals(path.document == doc2, true); + equals(function() { + return path.document == doc2; + }, true); doc2.activeLayer.appendTop(group); - equals(group.children[0].document == doc2, true); + equals(function() { + return group.children[0].document == doc2; + }, true); }); test('group.selected', function() { @@ -170,16 +261,27 @@ test('group.selected', function() { var path2 = new Path([0, 0]); var group = new Group([path, path2]); path.selected = true; - equals(group.selected, true); + equals(function() { + return group.selected; + }, true); path.selected = false; - equals(group.selected, false); + equals(function() { + return group.selected; + }, false); group.selected = true; - equals(path.selected, true); - equals(path2.selected, true); + equals(function() { + return path.selected; + }, true); + equals(function() { + return path2.selected; + }, true); group.selected = false; - equals(path.selected, false); - equals(path2.selected, false); -}); \ No newline at end of file + equals(function() { + return path.selected; + }, false); + equals(function() { + return path2.selected; + }, false);}); \ No newline at end of file diff --git a/test/tests/Layer.js b/test/tests/Layer.js index 9769e403..7eaf3677 100644 --- a/test/tests/Layer.js +++ b/test/tests/Layer.js @@ -4,23 +4,39 @@ test('previousSibling / nextSibling', function() { var doc = new Document(); var firstLayer = doc.activeLayer; var secondLayer = new Layer(); - equals(secondLayer.previousSibling == firstLayer, true); - equals(secondLayer.nextSibling == null, true); + equals(function() { + return secondLayer.previousSibling == firstLayer; + }, true); + equals(function() { + return secondLayer.nextSibling == null; + }, true); // Move another layer into secondLayer and check nextSibling / // previousSibling: var path = new Path(); var thirdLayer = new Layer(); secondLayer.appendBottom(thirdLayer); - equals(secondLayer.children.length, 2); - equals(thirdLayer.nextSibling == path, true); + equals(function() { + return secondLayer.children.length; + }, 2); + equals(function() { + return thirdLayer.nextSibling == path; + }, true); secondLayer.appendTop(thirdLayer); - equals(thirdLayer.nextSibling == null, true); - equals(thirdLayer.previousSibling == path, true); - equals(doc.layers.length == 2, true); + equals(function() { + return thirdLayer.nextSibling == null; + }, true); + equals(function() { + return thirdLayer.previousSibling == path; + }, true); + equals(function() { + return doc.layers.length == 2; + }, true); firstLayer.appendTop(secondLayer); - equals(doc.layers.length == 1, true); + equals(function() { + return doc.layers.length == 1; + }, true); }); test('moveAbove / moveBelow', function() { @@ -28,17 +44,26 @@ test('moveAbove / moveBelow', function() { var firstLayer = doc.activeLayer; var secondLayer = new Layer(); secondLayer.moveBelow(firstLayer); - equals(secondLayer.previousSibling == null, true); - equals(secondLayer.nextSibling == firstLayer, true); + equals(function() { + return secondLayer.previousSibling == null; + }, true); + equals(function() { + return secondLayer.nextSibling == firstLayer; + }, true); var path = new Path(); firstLayer.appendTop(path); // move the layer above the path, inside the firstLayer: secondLayer.moveAbove(path); - equals(secondLayer.previousSibling == path, true); - equals(secondLayer.parent == firstLayer, true); - + equals(function() { + return secondLayer.previousSibling == path; + }, true); + equals(function() { + return secondLayer.parent == firstLayer; + }, true); // There should now only be one layer left: - equals(doc.layers.length, 1); + equals(function() { + return doc.layers.length; + }, 1); }); \ No newline at end of file diff --git a/test/tests/Path.js b/test/tests/Path.js index f7306540..02ef2f83 100644 --- a/test/tests/Path.js +++ b/test/tests/Path.js @@ -12,7 +12,9 @@ test('path.join(path)', function() { path.join(path2); equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }'); - equals(doc.activeLayer.children.length, 1); + equals(function() { + return doc.activeLayer.children.length; + }, 1); var path = new Path(); path.add(0, 0); @@ -47,7 +49,9 @@ test('path.join(path)', function() { path.join(path2); equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } },{ point: { x: 10, y: 5 } }'); - equals(path.closed, true); + equals(function() { + return path.closed; + }, true); }); test('path.remove()', function() { @@ -59,17 +63,25 @@ test('path.remove()', function() { path.add(30, 0); path.removeSegment(0); - equals(path.segments.length, 3); + equals(function() { + return path.segments.length; + }, 3); path.removeSegment(0); - equals(path.segments.length, 2); + equals(function() { + return path.segments.length; + }, 2); path.removeSegments(0, 2); - equals(path.segments.length, 0); + equals(function() { + return path.segments.length; + }, 0); path.remove(); - equals(doc.activeLayer.children.length, 0); + equals(function() { + return doc.activeLayer.children.length; + }, 0); }); @@ -77,12 +89,20 @@ test('Is the path deselected after setting a new list of segments?', function() var doc = new Document(); var path = new Path([0, 0]); path.selected = true; - equals(path.selected, true); - equals(doc.selectedItems.length, 1); + equals(function() { + return path.selected; + }, true); + equals(function() { + return doc.selectedItems.length; + }, 1); path.segments = [[0, 10]]; - equals(path.selected, false); - equals(doc.selectedItems.length, 0); + equals(function() { + return path.selected; + }, false); + equals(function() { + return doc.selectedItems.length; + }, 0); }); test('Path#reverse', function() { diff --git a/test/tests/PathStyle.js b/test/tests/PathStyle.js index ec52d559..5fbcf4b1 100644 --- a/test/tests/PathStyle.js +++ b/test/tests/PathStyle.js @@ -62,7 +62,9 @@ test('getting group styles', function() { // the group now contains two paths with different fillColors and therefore // should return undefined: - equals(group.fillColor, undefined, 'group.fillColor'); + equals(function() { + return group.fillColor; + }, undefined); //If we remove the first path, it should now return 'black': group.children[0].remove(); @@ -112,7 +114,9 @@ test('setting group styles 2', function() { // By appending a path with a different fillcolor, // the group's fillColor should return undefined: - equals(group.fillColor, undefined, 'group.fillColor'); + equals(function() { + return group.fillColor; + }, undefined); // But, both paths have a red strokeColor, so: compareRGBColors(group.strokeColor, 'red', 'group.strokeColor'); diff --git a/test/tests/Rectangle.js b/test/tests/Rectangle.js index 1490f18b..d0ea5d1f 100644 --- a/test/tests/Rectangle.js +++ b/test/tests/Rectangle.js @@ -26,7 +26,9 @@ test('new Rectangle({x: 10, y: 20, width: 30, height: 40});', function() { test('get size', function() { var rect = new Rectangle(10, 10, 20, 30); - equals(rect.size.equals([20, 30]), true); + equals(function() { + return rect.size.equals([20, 30]); + }, true); }); test('set size', function() { @@ -142,55 +144,72 @@ test('set rightCenter', function() { test('intersects(rect)', function() { var rect1 = new Rectangle({ x: 160, y: 270, width: 20, height: 20 }); var rect2 = { x: 195, y: 301, width: 19, height: 19 }; - equals(rect1.intersects(rect2), false); - + equals(function() { + return rect1.intersects(rect2); + }, false); rect1 = new Rectangle({ x: 160, y: 270, width: 20, height: 20 }); rect2 = { x: 170.5, y: 280.5, width: 19, height: 19 }; - equals(rect1.intersects(rect2), true); + equals(function() { + return rect1.intersects(rect2); + }, true); }); test('contains(rect)', function() { var rect1 = new Rectangle({ x: 160, y: 270, width: 20, height: 20 }); var rect2 = { x: 195, y: 301, width: 19, height: 19 }; - equals(rect1.contains(rect2), false); - + equals(function() { + return rect1.contains(rect2); + }, false); rect1 = new Rectangle({ x: 160, y: 270, width: 20, height: 20 }); rect2 = new Rectangle({ x: 170.5, y: 280.5, width: 19, height: 19 }); - equals(rect1.contains(rect2), false); - + equals(function() { + return rect1.contains(rect2); + }, false); + rect1 = new Rectangle({ x: 299, y: 161, width: 137, height: 129 }); rect2 = new Rectangle({ x: 340, y: 197, width: 61, height: 61 }); - equals(rect1.contains(rect2), true); - equals(rect2.contains(rect1), false); -}); + equals(function() { + return rect1.contains(rect2); + }, true); + equals(function() { + return rect2.contains(rect1); + }, false);}); test('contains(point)', function() { var rect = new Rectangle({ x: 160, y: 270, width: 20, height: 20 }); var point = new Point(166, 280); - equals(rect.contains(point), true); - + equals(function() { + return rect.contains(point); + }, true); var point = new Point(30, 30); - equals(rect.contains(point), false); -}); + equals(function() { + return rect.contains(point); + }, false);}); test('intersect(rect)', function() { var rect1 = new Rectangle({ x: 160, y: 270, width: 20, height: 20 }); var rect2 = { x: 170.5, y: 280.5, width: 19, height: 19 }; var intersected = rect1.intersect(rect2); - equals(intersected.equals({ x: 170.5, y: 280.5, width: 9.5, height: 9.5 }), true); + equals(function() { + return intersected.equals({ x: 170.5, y: 280.5, width: 9.5, height: 9.5 }); + }, true); }); test('unite(rect)', function() { var rect1 = new Rectangle({ x: 160, y: 270, width: 20, height: 20 }); var rect2 = { x: 170.5, y: 280.5, width: 19, height: 19 }; var united = rect1.unite(rect2); - equals(united.equals({ x: 160, y: 270, width: 29.5, height: 29.5 }), true); + equals(function() { + return united.equals({ x: 160, y: 270, width: 29.5, height: 29.5 }); + }, true); }); test('include(point)', function() { var rect1 = new Rectangle({ x: 95, y: 151, width: 20, height: 20 }); var included = rect1.include([50, 50]); - equals(included.equals({ x: 50, y: 50, width: 65, height: 121 }), true); + equals(function() { + return included.equals({ x: 50, y: 50, width: 65, height: 121 }); + }, true); }); test('toString()', function() { diff --git a/test/tests/Segment.js b/test/tests/Segment.js index 149fd1e9..4a7a2dc4 100644 --- a/test/tests/Segment.js +++ b/test/tests/Segment.js @@ -33,8 +33,13 @@ test('segment.reverse()', function() { test('segment.clone()', function() { var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15)); var clone = segment.clone(); - equals(segment == clone, false); - equals(segment.toString(), clone.toString()); + equals(function() { + return segment == clone; + }, false); + + equals(function() { + return segment.toString(); + }, clone.toString()); }); test('segment.remove()', function() { @@ -46,8 +51,10 @@ test('segment.remove()', function() { test('segment.selected', function() { var path = new Path([10, 20], [50, 100]); path.segments[0].point.selected = true; - equals(path.segments[0].point.selected, true); - + equals(function() { + return path.segments[0].point.selected; + }, true); path.segments[0].point.selected = false; - equals(path.segments[0].point.selected, false); -}); \ No newline at end of file + equals(function() { + return path.segments[0].point.selected; + }, false);}); \ No newline at end of file