Skip to content

Commit 27e68dc

Browse files
committed
Basic unit tests
1 parent 69a50b3 commit 27e68dc

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
buster.spec.expose();
2+
3+
describe("purl in non-strict mode", function () {
4+
5+
before(function () {
6+
this.url = purl('http://allmarkedup.com/folder/dir/index.html?item=value#foo');
7+
});
8+
9+
it('should have a protocol of http', function() {
10+
expect(this.url.attr('protocol')).toBe('http');
11+
});
12+
13+
it('should have a path of /folder/dir/index.html', function() {
14+
expect(this.url.attr('path')).toBe('/folder/dir/index.html');
15+
});
16+
17+
/* should it? */
18+
it('should have an unset port', function() {
19+
expect(this.url.attr('port')).toBe('');
20+
});
21+
22+
it('should have an host of allmarkedup.com', function() {
23+
expect(this.url.attr('host')).toBe('allmarkedup.com');
24+
});
25+
26+
it('should have a relative path of /folder/dir/index.html?item=value#foo', function() {
27+
expect(this.url.attr('relative')).toBe('/folder/dir/index.html?item=value#foo');
28+
});
29+
30+
it('should have a path of /folder/dir/index.html', function() {
31+
expect(this.url.attr('path')).toBe('/folder/dir/index.html');
32+
});
33+
34+
it('should have a directory of /folder/dir/', function() {
35+
expect(this.url.attr('directory')).toBe('/folder/dir/');
36+
});
37+
38+
it('should have a file of index.html', function() {
39+
expect(this.url.attr('file')).toBe('index.html');
40+
});
41+
42+
it('should have a querystring of item=value', function() {
43+
expect(this.url.attr('query')).toBe('item=value');
44+
});
45+
46+
it('should have an anchor of foo', function() {
47+
expect(this.url.attr('anchor')).toBe('foo');
48+
expect(this.url.attr('fragment')).toBe('foo');
49+
});
50+
51+
it('should have a param() of item: "value"', function() {
52+
expect(this.url.param()).toBeObject({item: 'value'})
53+
});
54+
55+
it('should have a param("item") of "value"', function() {
56+
expect(this.url.param('item')).toBe('value')
57+
});
58+
59+
it('should have a segment() of ["folder","dir","index.html"]', function() {
60+
expect(this.url.segment()).toEqual(["folder","dir","index.html"])
61+
});
62+
63+
it('should have a segment(1) of "folder"', function() {
64+
expect(this.url.segment(1)).toBe("folder");
65+
});
66+
67+
it('should have a segment(-1) of "folder"', function() {
68+
expect(this.url.segment(-1)).toBe("index.html");
69+
});
70+
71+
});

test/base-tests.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function(url) {
2+
it('should have a protocol of http', function() {
3+
expect(url.attr('protocol')).toBe('http');
4+
});
5+
6+
it('should have a path of /folder/dir/index.html', function() {
7+
expect(url.attr('path')).toBe('/folder/dir/index.html');
8+
});
9+
10+
/* should it? */
11+
it('should have an unset port', function() {
12+
expect(url.attr('port')).toBe('');
13+
});
14+
15+
it('should have an host of allmarkedup.com', function() {
16+
expect(url.attr('host')).toBe('allmarkedup.com');
17+
});
18+
19+
it('should have a relative path of /folder/dir/index.html?item=value#foo', function() {
20+
expect(url.attr('relative')).toBe('/folder/dir/index.html?item=value#foo');
21+
});
22+
23+
it('should have a path of /folder/dir/index.html', function() {
24+
expect(url.attr('path')).toBe('/folder/dir/index.html');
25+
});
26+
27+
it('should have a directory of /folder/dir/', function() {
28+
expect(url.attr('directory')).toBe('/folder/dir/');
29+
});
30+
31+
it('should have a file of index.html', function() {
32+
expect(url.attr('file')).toBe('index.html');
33+
});
34+
35+
it('should have a querystring of item=value', function() {
36+
expect(url.attr('query')).toBe('item=value');
37+
});
38+
39+
it('should have an anchor of foo', function() {
40+
expect(url.attr('anchor')).toBe('foo');
41+
expect(url.attr('fragment')).toBe('foo');
42+
});
43+
44+
it('should have a param() of item: "value"', function() {
45+
expect(url.param()).toBeObject({item: 'value'})
46+
});
47+
48+
it('should have a param("item") of "value"', function() {
49+
expect(url.param('item')).toBe('value')
50+
});
51+
52+
it('should have a segment() of ["folder","dir","index.html"]', function() {
53+
expect(url.segment()).toEqual(["folder","dir","index.html"])
54+
});
55+
56+
it('should have a segment(1) of "folder"', function() {
57+
expect(url.segment(1)).toBe("folder");
58+
});
59+
60+
it('should have a segment(-1) of "folder"', function() {
61+
expect(url.segment(-1)).toBe("index.html");
62+
});
63+
}

test/buster.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var config = module.exports;
2+
3+
config["Tests"] = {
4+
rootPath: "../",
5+
environment: "browser",
6+
sources: [
7+
"purl.js"
8+
],
9+
tests: [
10+
"test/*-test.js"
11+
]
12+
}

0 commit comments

Comments
 (0)