Clarify some variable names in osmEntity.deprecatedTags and add more code tests

This commit is contained in:
Quincy Morgan
2020-01-09 09:49:31 -05:00
parent 1319700ce5
commit 5011039087
2 changed files with 48 additions and 12 deletions

View File

@@ -194,20 +194,22 @@ osmEntity.prototype = {
var deprecated = [];
dataDeprecated.forEach(function(d) {
var matchesDeprecatedTags = Object.keys(d.old).every(function(key) {
if (!tags[key]) return false;
if (d.old[key] === '*') return true;
var oldKeys = Object.keys(d.old);
var matchesDeprecatedTags = oldKeys.every(function(oldKey) {
if (!tags[oldKey]) return false;
if (d.old[oldKey] === '*') return true;
var vals = tags[key].split(';').filter(Boolean);
var vals = tags[oldKey].split(';').filter(Boolean);
if (vals.length === 0) {
return false;
} else if (vals.length > 1) {
return vals.indexOf(d.old[key]) !== -1;
return vals.indexOf(d.old[oldKey]) !== -1;
} else {
if (tags[key] === d.old[key]) {
if (d.replace && d.old[key] === d.replace[key]) {
return !Object.keys(d.replace).every(function(key) {
return tags[key] === d.replace[key];
if (tags[oldKey] === d.old[oldKey]) {
if (d.replace && d.old[oldKey] === d.replace[oldKey]) {
var replaceKeys = Object.keys(d.replace);
return !replaceKeys.every(function(replaceKey) {
return tags[replaceKey] === d.replace[replaceKey];
});
} else {
return true;

View File

@@ -221,16 +221,50 @@ describe('iD.osmEntity', function () {
});
});
describe('#hasDeprecatedTags', function () {
it('returns false if entity has no tags', function () {
describe('#deprecatedTags', function () {
it('returns none if entity has no tags', function () {
expect(iD.osmEntity().deprecatedTags()).to.eql([]);
});
it('returns true if entity has deprecated tags', function () {
it('returns none when no tags are deprecated', function () {
expect(iD.osmEntity({ tags: { amenity: 'toilets' } }).deprecatedTags()).to.eql([]);
});
it('returns 1:0 replacement', function () {
expect(iD.osmEntity({ tags: { highway: 'no' } }).deprecatedTags()).to.eql(
[{ old: { highway: 'no' } }]
);
});
it('returns 1:1 replacement', function () {
expect(iD.osmEntity({ tags: { amenity: 'toilet' } }).deprecatedTags()).to.eql(
[{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } }]
);
});
it('returns 1:1 wildcard', function () {
expect(iD.osmEntity({ tags: { speedlimit: '50' } }).deprecatedTags()).to.eql(
[{ old: { speedlimit: '*' }, replace: { maxspeed: '$1' } }]
);
});
it('returns 1:2 total replacement', function () {
expect(iD.osmEntity({ tags: { man_made: 'water_tank' } }).deprecatedTags()).to.eql(
[{ old: { man_made: 'water_tank' }, replace: { man_made: 'storage_tank', content: 'water' } }]
);
});
it('returns 1:2 partial replacement', function () {
expect(iD.osmEntity({ tags: { man_made: 'water_tank', content: 'water' } }).deprecatedTags()).to.eql(
[{ old: { man_made: 'water_tank' }, replace: { man_made: 'storage_tank', content: 'water' } }]
);
});
it('returns 2:1 replacement', function () {
expect(iD.osmEntity({ tags: { amenity: 'gambling', gambling: 'casino' } }).deprecatedTags()).to.eql(
[{ old: { amenity: 'gambling', gambling: 'casino' }, replace: { amenity: 'casino' } }]
);
});
});
describe('#hasWikidata', function () {