Expand util tests

This commit is contained in:
Tom MacWright
2013-01-02 13:26:36 -05:00
parent 60820234c7
commit 06c3caa1c0
2 changed files with 27 additions and 1 deletions
+3 -1
View File
@@ -45,7 +45,9 @@ iD.util.tagText = function(entity) {
iD.util.stringQs = function(str) {
return str.split('&').reduce(function(obj, pair){
var parts = pair.split('=');
obj[parts[0]] = (null === parts[1]) ? '' : decodeURIComponent(parts[1]);
if (parts.length === 2) {
obj[parts[0]] = (null === parts[1]) ? '' : decodeURIComponent(parts[1]);
}
return obj;
}, {});
};
+24
View File
@@ -6,6 +6,24 @@ describe('Util', function() {
expect(iD.util.trueObj([])).to.eql({});
});
it('#tagText', function() {
expect(iD.util.tagText({})).to.eql('');
expect(iD.util.tagText({tags:{foo:'bar'}})).to.eql('foo: bar');
expect(iD.util.tagText({tags:{foo:'bar',two:'three'}})).to.eql('foo: bar\ntwo: three');
});
it('#stringQs', function() {
expect(iD.util.stringQs('foo=bar')).to.eql({foo: 'bar'});
expect(iD.util.stringQs('foo=bar&one=2')).to.eql({foo: 'bar', one: '2' });
expect(iD.util.stringQs('')).to.eql({});
});
it('#qsString', function() {
expect(iD.util.qsString({ foo: 'bar' })).to.eql('foo=bar');
expect(iD.util.qsString({ foo: 'bar', one: 2 })).to.eql('foo=bar&one=2');
expect(iD.util.qsString({})).to.eql('');
});
it('#friendlyName', function() {
expect(iD.util.friendlyName({ tags: { name: 'hi' }})).to.equal('hi');
expect(iD.util.friendlyName({ tags: { highway: 'Route 5' }})).to.equal('Route 5');
@@ -13,6 +31,12 @@ describe('Util', function() {
});
describe('geo', function() {
describe('#roundCoords', function() {
expect(iD.util.geo.roundCoords([0.1, 1])).to.eql([0, 1]);
expect(iD.util.geo.roundCoords([0, 1])).to.eql([0, 1]);
expect(iD.util.geo.roundCoords([0, 1.1])).to.eql([0, 1]);
});
describe('#interp', function() {
it('interpolates halfway', function() {
var a = [0, 0],