diff --git a/comparators/added_ref_tag.js b/comparators/added_ref_tag.js new file mode 100644 index 0000000..1533d9d --- /dev/null +++ b/comparators/added_ref_tag.js @@ -0,0 +1,21 @@ +'use strict'; + +module.exports = addedPlace; + +function addedPlace(newVersion, oldVersion) { + if (newVersion.deleted) { + return false; + } + if (oldVersion) { + if ( + 'ref' in newVersion.properties && + !('ref' in oldVersion.properties) && + ('highway' in newVersion.properties || + ('route' in newVersion.properties && + newVersion.properties.route === 'road')) + ) { + return {'result:added_ref_tag': true}; + } + } + return false; +} diff --git a/comparators/deleted_ref_tag.js b/comparators/deleted_ref_tag.js new file mode 100644 index 0000000..7450564 --- /dev/null +++ b/comparators/deleted_ref_tag.js @@ -0,0 +1,21 @@ +'use strict'; + +module.exports = addedPlace; + +function addedPlace(newVersion, oldVersion) { + if (newVersion.deleted || !oldVersion) { + return false; + } + if (oldVersion) { + if ( + 'ref' in oldVersion.properties && + !('ref' in newVersion.properties) && + ('highway' in newVersion.properties || + ('route' in newVersion.properties && + newVersion.properties.route === 'road')) + ) { + return {'result:deleted_ref_tag': true}; + } + } + return false; +} diff --git a/index.js b/index.js index b3061ff..5e9cf96 100755 --- a/index.js +++ b/index.js @@ -28,6 +28,8 @@ module.exports = { require('./comparators/dragged_highway_waterway') ), added_place: wrapsync(require('./comparators/added_place')), + added_ref_tag: wrapsync(require('./comparators/added_ref_tag')), + deleted_ref_tag: wrapsync(require('./comparators/deleted_ref_tag')), modified_place_wikidata: wrapsync( require('./comparators/modified_place_wikidata') ), diff --git a/tests/fixtures/added_ref_tag.json b/tests/fixtures/added_ref_tag.json new file mode 100644 index 0000000..c199c7c --- /dev/null +++ b/tests/fixtures/added_ref_tag.json @@ -0,0 +1,289 @@ +{ + "compareFunction": "added_ref_tag", + "fixtures": [ + { + "description": "New object with ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "highway": "primary", + "ref": "BR-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "oldVersion": null, + "expectedResult": false + }, + { + "description": "Building receives ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "building": "yes", + "ref": "BR-001" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ], + [ + 83.33335071802139, + 17.7251960851791 + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "building": "yes" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ], + [ + 83.33335071802139, + 17.7251960851791 + ] + ] + } + }, + "expectedResult": false + }, + { + "description": "Route receives ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "type": "route", + "route": "road", + "ref": "BR-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "route": "road", + "type": "route" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "expectedResult": { + "result:added_ref_tag": true + } + }, + { + "description": "Existing object receives ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "highway": "primary", + "ref": "BR-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "highway": "primary" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "expectedResult": { + "result:added_ref_tag": true + } + }, + { + "description": "Changes in existing object with ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "highway": "secondary", + "ref": "BR-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "highway": "primary", + "ref": "BR-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "expectedResult": false + } + ] +} diff --git a/tests/fixtures/deleted_ref_tag.json b/tests/fixtures/deleted_ref_tag.json new file mode 100644 index 0000000..05b73af --- /dev/null +++ b/tests/fixtures/deleted_ref_tag.json @@ -0,0 +1,288 @@ +{ + "compareFunction": "deleted_ref_tag", + "fixtures": [ + { + "description": "New object without ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "highway": "primary" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "oldVersion": null, + "expectedResult": false + }, + { + "description": "Object loses ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "highway": "primary" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "highway": "primary", + "ref": "BR-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "expectedResult": { + "result:deleted_ref_tag": true + } + }, + { + "description": "Building loses ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "building": "yes" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ], + [ + 83.33335071802139, + 17.7251960851791 + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "building": "yes", + "ref": "BR-010" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ], + [ + 83.33335071802139, + 17.7251960851791 + ] + ] + } + }, + "expectedResult": false + }, + { + "description": "Route loses ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "type": "route", + "route": "road" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "route": "road", + "type": "route", + "ref": "BA-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "expectedResult": { + "result:deleted_ref_tag": true + } + }, + { + "description": "Changes in existing object with ref tag", + "newVersion": { + "type": "Feature", + "properties": { + "highway": "secondary", + "ref": "BR-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "oldVersion": { + "type": "Feature", + "properties": { + "highway": "primary", + "ref": "BR-001" + }, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 83.33335071802139, + 17.7251960851791 + ], + [ + 83.33353847265244, + 17.725829693891324 + ], + [ + 83.33366185426712, + 17.726299789230563 + ], + [ + 83.33373963832855, + 17.726568049605337 + ] + ] + } + }, + "expectedResult": false + } + ] +}