aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVojta Jina2010-10-18 20:35:31 +0100
committerIgor Minar2010-10-19 21:58:01 -0700
commita27198d52e61adb9cedde04e51bbec74e66089da (patch)
tree3bbc52653727dca6f243f84bc55b60691088146b /test
parent286d1fe434687a1c0e3ddc6cf7214896704d97b3 (diff)
downloadangular.js-a27198d52e61adb9cedde04e51bbec74e66089da.tar.bz2
Added tests for URL_MATCH and fixed issue with empty path
This commit was produced by a combination of 4 commits: - Added URL_MATCH test for basic url - Moved two tests from $location to URL_MATCH, as they should be here - Added test for host without "/" ending and fix the regexp to pass the test - Added another test for matching empty abs path ("/") and fix the regexp
Diffstat (limited to 'test')
-rw-r--r--test/servicesSpec.js72
1 files changed, 51 insertions, 21 deletions
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index cf45becb..1f30b969 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -128,19 +128,6 @@ describe("service", function(){
expect($browser.getUrl()).toEqual('http://www.angularjs.org/a/b');
});
- it('should parse file://', function(){
- scope.$location.update('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
- expect(scope.$location.href).toEqual("file:///Users/Shared/misko/work/angular.js/scenario/widgets.html");
- expect(scope.$location.protocol).toEqual("file");
- expect(scope.$location.host).toEqual("");
- expect(scope.$location.port).toEqual(null);
- expect(scope.$location.path).toEqual("/Users/Shared/misko/work/angular.js/scenario/widgets.html");
- expect(scope.$location.search).toEqual({});
- expect(scope.$location.hash).toEqual('');
- expect(scope.$location.hashPath).toEqual('');
- expect(scope.$location.hashSearch).toEqual({});
- });
-
it('should update hashPath and hashSearch on hash update', function(){
scope.$location.update('http://server/#path?a=b');
scope.$eval();
@@ -178,14 +165,6 @@ describe("service", function(){
expect(scope.$location.hash).toEqual('');
});
- it("should parse url which contains - in host", function(){
- scope.$location.update('http://a-b1.c-d.09/path');
- expect(scope.$location.href).toEqual('http://a-b1.c-d.09/path');
- expect(scope.$location.protocol).toEqual('http');
- expect(scope.$location.host).toEqual('a-b1.c-d.09');
- expect(scope.$location.path).toEqual('/path');
- });
-
it('should update hash before any processing', function(){
var scope = compile('<div>');
var log = '';
@@ -582,4 +561,55 @@ describe("service", function(){
});
});
+
+
+ describe('URL_MATCH', function() {
+
+ it('should parse basic url', function() {
+ var match = URL_MATCH.exec('http://www.angularjs.org/path?search#hash?x=x');
+
+ expect(match[1]).toEqual('http');
+ expect(match[3]).toEqual('www.angularjs.org');
+ expect(match[6]).toEqual('/path');
+ expect(match[8]).toEqual('search');
+ expect(match[10]).toEqual('hash?x=x');
+ });
+
+ it('should parse file://', function(){
+ var match = URL_MATCH.exec('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
+
+ expect(match[1]).toEqual('file');
+ expect(match[3]).toEqual('');
+ expect(match[5]).toEqual(null);
+ expect(match[6]).toEqual('/Users/Shared/misko/work/angular.js/scenario/widgets.html');
+ expect(match[8]).not.toBeDefined();
+ });
+
+ it('should parse url with "-" in host', function(){
+ var match = URL_MATCH.exec('http://a-b1.c-d.09/path');
+
+ expect(match[1]).toEqual('http');
+ expect(match[3]).toEqual('a-b1.c-d.09');
+ expect(match[5]).toEqual(null);
+ expect(match[6]).toEqual('/path');
+ expect(match[8]).not.toBeDefined();
+ });
+
+ it('should parse host without "/" at the end', function() {
+ var match = URL_MATCH.exec('http://host.org');
+ expect(match[3]).toEqual('host.org');
+
+ match = URL_MATCH.exec('http://host.org#');
+ expect(match[3]).toEqual('host.org');
+
+ match = URL_MATCH.exec('http://host.org?');
+ expect(match[3]).toEqual('host.org');
+ });
+
+ it('should match with just "/" path', function() {
+ var match = URL_MATCH.exec('http://server/#?book=moby');
+
+ expect(match[10]).toEqual('?book=moby');
+ });
+ });
});