Speedup hot code in actionDiscardTags

(re: #4611)
This commit is contained in:
Bryan Housel
2018-02-04 14:57:26 -05:00
parent 42dd36addb
commit dac753c4ea
5 changed files with 135 additions and 131 deletions
+16 -16
View File
@@ -1,33 +1,33 @@
describe('iD.actionDiscardTags', function() {
it('discards obsolete tags from modified entities', function() {
var way = iD.Way({id: 'w1', tags: {created_by: 'Potlatch'}}),
base = iD.Graph([way]),
head = base.replace(way.update({tags: {created_by: 'Potlatch', foo: 'bar'}})),
action = iD.actionDiscardTags(iD.Difference(base, head));
var way = iD.osmWay({ id: 'w1', tags: { created_by: 'Potlatch' } });
var base = iD.coreGraph([way]);
var head = base.replace(way.update({ tags: { created_by: 'Potlatch', foo: 'bar' } }));
var action = iD.actionDiscardTags(iD.coreDifference(base, head));
expect(action(head).entity(way.id).tags).to.eql({foo: 'bar'});
});
it('discards obsolete tags from created entities', function() {
var way = iD.Way({tags: {created_by: 'Potlatch'}}),
base = iD.Graph(),
head = base.replace(way),
action = iD.actionDiscardTags(iD.Difference(base, head));
var way = iD.osmWay({ tags: { created_by: 'Potlatch' } });
var base = iD.coreGraph();
var head = base.replace(way);
var action = iD.actionDiscardTags(iD.coreDifference(base, head));
expect(action(head).entity(way.id).tags).to.eql({});
});
it('doesn\'t modify entities without obsolete tags', function() {
var way = iD.Way(),
base = iD.Graph(),
head = base.replace(way),
action = iD.actionDiscardTags(iD.Difference(base, head));
var way = iD.osmWay();
var base = iD.coreGraph();
var head = base.replace(way);
var action = iD.actionDiscardTags(iD.coreDifference(base, head));
expect(action(head).entity(way.id)).to.equal(way);
});
it('discards tags with empty values', function() {
var way = iD.Way({tags: {lmnop: ''}}),
base = iD.Graph(),
head = base.replace(way),
action = iD.actionDiscardTags(iD.Difference(base, head));
var way = iD.osmWay({ tags: { lmnop: '' } });
var base = iD.coreGraph();
var head = base.replace(way);
var action = iD.actionDiscardTags(iD.coreDifference(base, head));
expect(action(head).entity(way.id).tags).to.eql({});
});
});