From eb8d46d380a2005dbec3973d40e1dbc27991fdb7 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 27 Sep 2010 16:00:05 -0700 Subject: Differentiate between flags and empty keys in $location.hashSearch * #foo?key=var&flag&emptyKey= should parse into {key:'val', flag: true, emptyKey: ''} * added docs and spec for parseKeyValue function --- test/AngularSpec.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test/AngularSpec.js') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index b4e90175..725e8ea0 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -79,5 +79,17 @@ describe('equals', function(){ expect(equals({name:'misko'}, {name:'misko', $id:2})).toEqual(true); expect(equals({name:'misko', $id:1}, {name:'misko'})).toEqual(true); }); - }); + +describe('parseKeyValue', function() { + it('should parse a string into key-value pairs', function() { + expect(parseKeyValue('')).toEqual({}); + expect(parseKeyValue('simple=pair')).toEqual({simple: 'pair'}); + expect(parseKeyValue('first=1&second=2')).toEqual({first: '1', second: '2'}); + expect(parseKeyValue('escaped%20key=escaped%20value')). + toEqual({'escaped key': 'escaped value'}); + expect(parseKeyValue('emptyKey=')).toEqual({emptyKey: ''}); + expect(parseKeyValue('flag1&key=value&flag2')). + toEqual({flag1: true, key: 'value', flag2: true}); + }); +}) -- cgit v1.2.3