aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorIgor Minar2010-09-27 16:00:05 -0700
committerMisko Hevery2010-09-29 09:52:03 -0700
commiteb8d46d380a2005dbec3973d40e1dbc27991fdb7 (patch)
tree59a3e8d7bba0c4704b759efb38d1c72e5a85dc75 /test
parent984acdc6270df1dee5796ed44efebfb9ff6706c7 (diff)
downloadangular.js-eb8d46d380a2005dbec3973d40e1dbc27991fdb7.tar.bz2
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
Diffstat (limited to 'test')
-rw-r--r--test/AngularSpec.js14
-rw-r--r--test/servicesSpec.js12
2 files changed, 20 insertions, 6 deletions
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});
+ });
+})
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index f40b8f5e..04aebce7 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -77,21 +77,23 @@ describe("service", function(){
describe("$location", function(){
it("should inject $location", function(){
- scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value');
- expect(scope.$location.href).toEqual("http://host:123/p/a/t/h.html?query=value#path?key=value");
+ scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2=');
+ expect(scope.$location.href).
+ toEqual("http://host:123/p/a/t/h.html?query=value#path?key=value&flag&key2=");
expect(scope.$location.protocol).toEqual("http");
expect(scope.$location.host).toEqual("host");
expect(scope.$location.port).toEqual("123");
expect(scope.$location.path).toEqual("/p/a/t/h.html");
expect(scope.$location.search).toEqual({query:'value'});
- expect(scope.$location.hash).toEqual('path?key=value');
+ expect(scope.$location.hash).toEqual('path?key=value&flag&key2=');
expect(scope.$location.hashPath).toEqual('path');
- expect(scope.$location.hashSearch).toEqual({key:'value'});
+ expect(scope.$location.hashSearch).toEqual({key: 'value', flag: true, key2: ''});
scope.$location.hashPath = 'page=http://path';
scope.$location.hashSearch = {k:'a=b'};
- expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page%3Dhttp%3A//path?k=a%3Db');
+ expect(scope.$location.toString()).
+ toEqual('http://host:123/p/a/t/h.html?query=value#page%3Dhttp%3A//path?k=a%3Db');
});
it('should parse file://', function(){