From cc3b5732e7f3c3fc7a9712d7a7d3733854aa3ff6 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 1 Feb 2012 15:54:28 -0800 Subject: [PATCH] Point.toEqual will return true if it matches an array `new Point(1,2)` is equivalent to `[1,2]`. --- spec/atom/point-spec.coffee | 11 +++++++++++ src/atom/point.coffee | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/atom/point-spec.coffee b/spec/atom/point-spec.coffee index c4d095775..0b6852e3b 100644 --- a/spec/atom/point-spec.coffee +++ b/spec/atom/point-spec.coffee @@ -1,6 +1,17 @@ Point = require 'point' describe "Point", -> + describe ".isEqual(value)", -> + describe "when given value is a Point", -> + it "returns true when the rows and columns match", -> + expect(new Point(1,2)).toEqual new Point(1,2) + expect(new Point(2,1)).not.toEqual new Point(1,2) + + describe "when given value is an Array", -> + it "returns true only when index zero matches row and index one matches column", -> + expect(new Point(1,2)).toEqual [1,2] + expect(new Point(2,1)).not.toEqual [1,2] + describe "compare", -> it "returns 1, 0, or -1 based on whether the given point precedes, equals, or follows the receivers location in the buffer", -> expect(new Point(5, 0).compare(new Point(5, 0))).toBe 0 diff --git a/src/atom/point.coffee b/src/atom/point.coffee index 8e1076f9a..3c3f7d103 100644 --- a/src/atom/point.coffee +++ b/src/atom/point.coffee @@ -14,7 +14,10 @@ class Point constructor: (@row, @column) -> isEqual: (other) -> - @row == other.row && @column == other.column + if other instanceof Array + @row == other[0] and @column == other[1] + else + @row == other.row and @column == other.column compare: (other) -> if @row > other.row