diff options
Diffstat (limited to 'test/AngularSpec.js')
| -rw-r--r-- | test/AngularSpec.js | 21 | 
1 files changed, 19 insertions, 2 deletions
| diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 6384302c..9686ffd6 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -318,10 +318,21 @@ describe('angular', function() {        expect(parseKeyValue('invalid=%')).toEqual({ invalid: undefined });        expect(parseKeyValue('invalid=%&valid=good')).toEqual({ invalid: undefined, valid: 'good' });      }); +    it('should parse a string into key-value pairs with duplicates grouped in an array', function() { +      expect(parseKeyValue('')).toEqual({}); +      expect(parseKeyValue('duplicate=pair')).toEqual({duplicate: 'pair'}); +      expect(parseKeyValue('first=1&first=2')).toEqual({first: ['1','2']}); +      expect(parseKeyValue('escaped%20key=escaped%20value&&escaped%20key=escaped%20value2')). +      toEqual({'escaped key': ['escaped value','escaped value2']}); +      expect(parseKeyValue('flag1&key=value&flag1')). +      toEqual({flag1: [true,true], key: 'value'}); +      expect(parseKeyValue('flag1&flag1=value&flag1=value2&flag1')). +      toEqual({flag1: [true,'value','value2',true]}); +    });    });    describe('toKeyValue', function() { -    it('should parse key-value pairs into string', function() { +    it('should serialize key-value pairs into string', function() {        expect(toKeyValue({})).toEqual('');        expect(toKeyValue({simple: 'pair'})).toEqual('simple=pair');        expect(toKeyValue({first: '1', second: '2'})).toEqual('first=1&second=2'); @@ -330,9 +341,15 @@ describe('angular', function() {        expect(toKeyValue({emptyKey: ''})).toEqual('emptyKey=');      }); -    it('should parse true values into flags', function() { +    it('should serialize true values into flags', function() {        expect(toKeyValue({flag1: true, key: 'value', flag2: true})).toEqual('flag1&key=value&flag2');      }); + +    it('should serialize duplicates into duplicate param strings', function() { +      expect(toKeyValue({key: [323,'value',true]})).toEqual('key=323&key=value&key'); +      expect(toKeyValue({key: [323,'value',true, 1234]})). +      toEqual('key=323&key=value&key&key=1234'); +  });    }); | 
