-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathgetContentMeta.js
More file actions
109 lines (97 loc) · 2.98 KB
/
getContentMeta.js
File metadata and controls
109 lines (97 loc) · 2.98 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var assert = require('assert');
var getContentMeta = require('../lib/getContentMeta');
describe('getContentMeta', function() {
it('finds doctype by content type', function() {
assert.strictEqual(
getContentMeta(null, 'text/html').doctype,
'<!DOCTYPE html>'
);
assert.strictEqual(
getContentMeta(null, 'application/xhtml+xml').doctype,
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
);
assert.strictEqual(
getContentMeta(null, 'image/svg+xml').doctype,
''
);
});
it('finds content type by full doctype', function() {
assert.strictEqual(
getContentMeta(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
).contentType,
'text/html'
);
});
it("doesn't find a match for an empty doctype", function() { // Even though it matches SVG
assert.throws(
function() { getContentMeta(''); },
/Could not find matching content type/
);
});
it("doesn't find a match for an nonsense doctype", function() {
assert.throws(
function() { getContentMeta('missingno'); },
/Could not find matching content type/
);
});
it("doesn't find a match for an nonsense content type", function() {
assert.throws(
function() { getContentMeta(null, 'missingno'); },
/Could not find matching doctype/
);
});
it('finds content type by doctype nickname', function() {
assert.strictEqual(
getContentMeta(5).contentType,
'text/html'
);
assert.strictEqual(
getContentMeta('html5').contentType,
'text/html'
);
assert.strictEqual(
getContentMeta('svg').contentType,
'image/svg+xml'
);
});
it('finds actual doctype by doctype nickname', function() {
assert.strictEqual(
getContentMeta(4).doctype,
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
);
assert.strictEqual(
getContentMeta('svg').doctype,
''
);
assert.strictEqual(
getContentMeta(4, 'text/html').doctype,
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
);
assert.deepEqual(
getContentMeta('strict', 'text/html'),
{
doctype: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
contentType: 'text/html'
}
);
});
it('defaults to html5', function() {
assert.deepEqual(
getContentMeta(),
{doctype: '<!DOCTYPE html>', contentType: 'text/html'}
);
});
it('defaults to html5', function() {
assert.deepEqual(
getContentMeta(),
{doctype: '<!DOCTYPE html>', contentType: 'text/html'}
);
});
it('passes through explicit values', function() {
assert.deepEqual(
getContentMeta('hello', 'goodbye'),
{doctype: 'hello', contentType: 'goodbye'}
);
});
});