aboutsummaryrefslogtreecommitdiff
path: root/node_modules/url-join/test
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/url-join/test
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/url-join/test')
-rw-r--r--node_modules/url-join/test/tests.js131
1 files changed, 131 insertions, 0 deletions
diff --git a/node_modules/url-join/test/tests.js b/node_modules/url-join/test/tests.js
new file mode 100644
index 00000000..fd16044f
--- /dev/null
+++ b/node_modules/url-join/test/tests.js
@@ -0,0 +1,131 @@
+var urljoin = require('../lib/url-join');
+
+describe('url join', function () {
+ it('should work for simple case', function () {
+ urljoin('http://www.google.com/', 'foo/bar', '?test=123')
+ .should.eql('http://www.google.com/foo/bar?test=123');
+ });
+
+ it('should work for simple case with new syntax', function () {
+ urljoin(['http://www.google.com/', 'foo/bar', '?test=123'])
+ .should.eql('http://www.google.com/foo/bar?test=123');
+ });
+
+ it('should work for hashbang urls', function () {
+ urljoin(['http://www.google.com', '#!', 'foo/bar', '?test=123'])
+ .should.eql('http://www.google.com/#!/foo/bar?test=123');
+ });
+
+ it('should be able to join protocol', function () {
+ urljoin('http:', 'www.google.com/', 'foo/bar', '?test=123')
+ .should.eql('http://www.google.com/foo/bar?test=123');
+ });
+
+ it('should be able to join protocol with slashes', function () {
+ urljoin('http://', 'www.google.com/', 'foo/bar', '?test=123')
+ .should.eql('http://www.google.com/foo/bar?test=123');
+ });
+
+ it('should remove extra slashes', function () {
+ urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123')
+ .should.eql('http://www.google.com/foo/bar?test=123');
+ });
+
+ it('should not remove extra slashes in an encoded URL', function () {
+ urljoin('http:', 'www.google.com///', 'foo/bar', '?url=http%3A//Ftest.com')
+ .should.eql('http://www.google.com/foo/bar?url=http%3A//Ftest.com');
+
+ urljoin('http://a.com/23d04b3/', '/b/c.html')
+ .should.eql('http://a.com/23d04b3/b/c.html')
+ .should.not.eql('http://a.com/23d04b3//b/c.html');
+ });
+
+ it('should support anchors in urls', function () {
+ urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '#faaaaa')
+ .should.eql('http://www.google.com/foo/bar?test=123#faaaaa');
+ });
+
+ it('should support protocol-relative urls', function () {
+ urljoin('//www.google.com', 'foo/bar', '?test=123')
+ .should.eql('//www.google.com/foo/bar?test=123')
+ });
+
+ it('should support file protocol urls', function () {
+ urljoin('file:/', 'android_asset', 'foo/bar')
+ .should.eql('file://android_asset/foo/bar')
+
+ urljoin('file:', '/android_asset', 'foo/bar')
+ .should.eql('file://android_asset/foo/bar')
+ });
+
+ it('should support absolute file protocol urls', function () {
+ urljoin('file:', '///android_asset', 'foo/bar')
+ .should.eql('file:///android_asset/foo/bar')
+
+ urljoin('file:///', 'android_asset', 'foo/bar')
+ .should.eql('file:///android_asset/foo/bar')
+
+ urljoin('file:///', '//android_asset', 'foo/bar')
+ .should.eql('file:///android_asset/foo/bar')
+
+ urljoin('file:///android_asset', 'foo/bar')
+ .should.eql('file:///android_asset/foo/bar')
+ });
+
+ it('should merge multiple query params properly', function () {
+ urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?key=456')
+ .should.eql('http://www.google.com/foo/bar?test=123&key=456');
+
+ urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?boom=value', '&key=456')
+ .should.eql('http://www.google.com/foo/bar?test=123&boom=value&key=456');
+
+ urljoin('http://example.org/x', '?a=1', '?b=2', '?c=3', '?d=4')
+ .should.eql('http://example.org/x?a=1&b=2&c=3&d=4');
+ });
+
+ it('should merge slashes in paths correctly', function () {
+ urljoin('http://example.org', 'a//', 'b//', 'A//', 'B//')
+ .should.eql('http://example.org/a/b/A/B/');
+ });
+
+ it('should merge colons in paths correctly', function () {
+ urljoin('http://example.org/', ':foo:', 'bar')
+ .should.eql('http://example.org/:foo:/bar');
+ });
+
+ it('should merge just a simple path without URL correctly', function() {
+ urljoin('/', 'test')
+ .should.eql('/test');
+ });
+
+ it('should merge a simple path with a number correctly', function() {
+ urljoin('http://blabla.com/', 1)
+ .should.eql('http://blabla.com/1');
+ });
+
+ it('should merge a path with colon properly', function(){
+ urljoin('/users/:userId', '/cars/:carId')
+ .should.eql('/users/:userId/cars/:carId');
+ });
+
+ it('should merge slashes in protocol correctly', function () {
+ urljoin('http://example.org', 'a')
+ .should.eql('http://example.org/a');
+ urljoin('http:', '//example.org', 'a')
+ .should.eql('http://example.org/a');
+ urljoin('http:///example.org', 'a')
+ .should.eql('http://example.org/a');
+ urljoin('file:///example.org', 'a')
+ .should.eql('file:///example.org/a');
+
+ urljoin('file:example.org', 'a')
+ .should.eql('file://example.org/a');
+
+ urljoin('file:/', 'example.org', 'a')
+ .should.eql('file://example.org/a');
+ urljoin('file:', '/example.org', 'a')
+ .should.eql('file://example.org/a');
+ urljoin('file:', '//example.org', 'a')
+ .should.eql('file://example.org/a');
+ });
+});