forked from broofa/mime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
75 lines (54 loc) · 1.88 KB
/
test.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
67
68
69
70
71
72
73
74
75
var mime = require('./mime');
debugger;
exports["test mime lookup"] = function(test) {
// easy
test.equal('text/plain', mime.lookup('text.txt'));
// hidden file or multiple periods
test.equal('text/plain', mime.lookup('.text.txt'));
// just an extension
test.equal('text/plain', mime.lookup('.txt'));
// just an extension without a dot
test.equal('text/plain', mime.lookup('txt'));
// default
test.equal('application/octet-stream', mime.lookup('text.nope'));
// fallback
test.equal('fallback', mime.lookup('text.fallback', 'fallback'));
test.finish();
};
exports["test extension lookup"] = function(test) {
// easy
test.equal('txt', mime.extension(mime.types.text));
test.equal('html', mime.extension(mime.types.htm));
test.equal('buffer', mime.extension('application/octet-stream'));
test.finish();
};
exports["test mime lookup uppercase"] = function(test) {
// easy
test.equal('text/plain', mime.lookup('TEXT.TXT'));
// just an extension
test.equal('text/plain', mime.lookup('.TXT'));
// just an extension without a dot
test.equal('text/plain', mime.lookup('TXT'));
// default
test.equal('application/octet-stream', mime.lookup('TEXT.NOPE'));
// fallback
test.equal('fallback', mime.lookup('TEXT.FALLBACK', 'fallback'));
test.finish();
};
exports["test custom types"] = function(test) {
test.equal('application/octet-stream', mime.lookup('file.buffer'));
test.equal('audio/mp4', mime.lookup('file.m4a'));
test.finish();
};
exports["test charset lookup"] = function(test) {
// easy
test.equal('UTF-8', mime.charsets.lookup('text/plain'));
// none
test.ok(typeof mime.charsets.lookup(mime.types.js) == 'undefined');
// fallback
test.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
test.finish();
};
if (module == require.main) {
require('async_testing').run(__filename, process.ARGV);
}