forked from helpers/handlebars-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.js
66 lines (58 loc) · 2.35 KB
/
url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
var assert = require('assert');
var hbs = require('handlebars');
var helpers = require('..');
helpers.url({handlebars: hbs});
describe('url', function() {
describe('urlResolve', function() {
it('should take a base URL, and a href URL, and resolve them as a browser would', function() {
var fn = hbs.compile('{{urlResolve "/one/two/three" "four"}}');
assert.equal(fn(), '/one/two/four');
});
it('should take a base URL, and a href URL, and resolve them as a browser would', function() {
var fn = hbs.compile('{{urlResolve "http://example.com/" "/one"}}');
assert.equal(fn(), 'http://example.com/one');
});
it('should take a base URL, and a href URL, and resolve them as a browser would', function() {
var fn = hbs.compile('{{urlResolve "http://example.com/one" "/two"}}');
assert.equal(fn(), 'http://example.com/two');
});
});
describe('stripQuerystring', function() {
it('should return a url without its query string.', function() {
var fn = hbs.compile('{{stripQuerystring "http://example.com?tests=true"}}');
assert.equal(fn(), 'http://example.com');
});
});
describe('encodeURI', function() {
it('should return an encoded uri string.', function() {
var fn = hbs.compile('{{encodeURI "http://example.com?comment=Thyme &time=again"}}');
assert.equal(fn(), 'http%3A%2F%2Fexample.com%3Fcomment%3DThyme%20%26time%3Dagain');
});
});
describe('decodeURI', function() {
it('should return an decoded uri string.', function() {
var fn = hbs.compile('{{{decodeURI "http%3A%2F%2Fexample.com%3Fcomment%3DThyme%20%26time%3Dagain"}}}');
assert.equal(fn(), 'http://example.com?comment=Thyme &time=again');
});
});
describe('urlParse', function() {
it('should take a string, and return an object stringified to JSON.', function() {
var fn = hbs.compile('{{{JSONstringify (urlParse "http://foo.com/bar/baz?key=value" "json")}}}');
JSON.parse(fn()).should.eql({
"protocol": "http:",
"slashes": true,
"auth": null,
"host": "foo.com",
"port": null,
"hostname": "foo.com",
"hash": null,
"search": "?key=value",
"query": "key=value",
"pathname": "/bar/baz",
"path": "/bar/baz?key=value",
"href": "http://foo.com/bar/baz?key=value"
});
});
});
});