From 31502c6214b82c7ecb7dd44a687630b4bc81d6d0 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 28 Dec 2012 22:13:36 -0800 Subject: [PATCH] Simplify; test; fix --- js/id/graph/entity.js | 15 ++++++--------- test/spec/graph/way.js | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/js/id/graph/entity.js b/js/id/graph/entity.js index f6be3905c..ce3197c99 100644 --- a/js/id/graph/entity.js +++ b/js/id/graph/entity.js @@ -129,11 +129,11 @@ iD.Way = iD.Entity.extend({ nodes: [], isOneWay: function() { - return !!(this.tags.oneway && this.tags.oneway === 'yes'); + return this.tags.oneway === 'yes'; }, isClosed: function() { - return (!this.nodes.length) || this.nodes[this.nodes.length - 1] === this.nodes[0]; + return this.nodes.length > 0 && this.nodes[this.nodes.length - 1] === this.nodes[0]; }, // a way is an area if: @@ -143,14 +143,11 @@ iD.Way = iD.Entity.extend({ // - doesn't have area=no // - doesn't have highway tag isArea: function() { - return (this.tags.area && this.tags.area === 'yes') || + return this.tags.area === 'yes' || (this.isClosed() && - // area-ness is disabled - (!this.tags.area || this.tags.area !== 'no') && - // Tags that disable area-ness unless they are accompanied by - // area=yes - !this.tags.highway && - !this.tags.barrier); + this.tags.area !== 'no' && + !this.tags.highway && + !this.tags.barrier); } }); diff --git a/test/spec/graph/way.js b/test/spec/graph/way.js index 022893d31..bb96a322d 100644 --- a/test/spec/graph/way.js +++ b/test/spec/graph/way.js @@ -52,6 +52,10 @@ describe('iD.Way', function() { }); describe('#isClosed', function() { + it('returns false when the way has no nodes', function() { + expect(iD.Way().isClosed()).to.equal(false); + }); + it('returns false when the way ends are not equal', function() { expect(iD.Way({nodes: ['n1', 'n2']}).isClosed()).to.equal(false); }); @@ -74,4 +78,26 @@ describe('iD.Way', function() { expect(iD.Way({tags: { oneway: 'yes' }}).isOneWay()).to.equal(true); }); }); + + describe('#isArea', function() { + it('returns false when the way has no tags', function() { + expect(iD.Way().isArea()).to.equal(false); + }); + + it('returns true if the way has tag area=yes', function() { + expect(iD.Way({tags: { area: 'yes' }}).isArea()).to.equal(true); + }); + + it('returns true if the way is closed and has no tags', function() { + expect(iD.Way({nodes: ['n1', 'n1']}).isArea()).to.equal(true); + }); + + it('returns false if the way is closed and has tag area=no', function() { + expect(iD.Way({tags: { area: 'no' }, nodes: ['n1', 'n1']}).isArea()).to.equal(false); + }); + + it('returns false if the way is closed and has highway tag', function() { + expect(iD.Way({tags: { highway: 'residential' }, nodes: ['n1', 'n1']}).isArea()).to.equal(false); + }); + }); });