~ps-jenkins/ubuntu-push/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to docs/example-server/node_modules/express/node_modules/send/node_modules/mime/test.js

  • Committer: Roberto Alsina
  • Date: 2014-09-05 14:57:17 UTC
  • mto: (91.179.25 automatic)
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: roberto.alsina@canonical.com-20140905145717-0ufcsv27w25i1nnu
added example app server

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Usage: node test.js
 
3
 */
 
4
 
 
5
var mime = require('./mime');
 
6
var assert = require('assert');
 
7
var path = require('path');
 
8
 
 
9
function eq(a, b) {
 
10
  console.log('Test: ' + a + ' === ' + b);
 
11
  assert.strictEqual.apply(null, arguments);
 
12
}
 
13
 
 
14
console.log(Object.keys(mime.extensions).length + ' types');
 
15
console.log(Object.keys(mime.types).length + ' extensions\n');
 
16
 
 
17
//
 
18
// Test mime lookups
 
19
//
 
20
 
 
21
eq('text/plain', mime.lookup('text.txt'));     // normal file
 
22
eq('text/plain', mime.lookup('TEXT.TXT'));     // uppercase
 
23
eq('text/plain', mime.lookup('dir/text.txt')); // dir + file
 
24
eq('text/plain', mime.lookup('.text.txt'));    // hidden file
 
25
eq('text/plain', mime.lookup('.txt'));         // nameless
 
26
eq('text/plain', mime.lookup('txt'));          // extension-only
 
27
eq('text/plain', mime.lookup('/txt'));         // extension-less ()
 
28
eq('text/plain', mime.lookup('\\txt'));        // Windows, extension-less
 
29
eq('application/octet-stream', mime.lookup('text.nope')); // unrecognized
 
30
eq('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
 
31
 
 
32
//
 
33
// Test extensions
 
34
//
 
35
 
 
36
eq('txt', mime.extension(mime.types.text));
 
37
eq('html', mime.extension(mime.types.htm));
 
38
eq('bin', mime.extension('application/octet-stream'));
 
39
eq('bin', mime.extension('application/octet-stream '));
 
40
eq('html', mime.extension(' text/html; charset=UTF-8'));
 
41
eq('html', mime.extension('text/html; charset=UTF-8 '));
 
42
eq('html', mime.extension('text/html; charset=UTF-8'));
 
43
eq('html', mime.extension('text/html ; charset=UTF-8'));
 
44
eq('html', mime.extension('text/html;charset=UTF-8'));
 
45
eq('html', mime.extension('text/Html;charset=UTF-8'));
 
46
eq(undefined, mime.extension('unrecognized'));
 
47
 
 
48
//
 
49
// Test node.types lookups
 
50
//
 
51
 
 
52
eq('application/font-woff', mime.lookup('file.woff'));
 
53
eq('application/octet-stream', mime.lookup('file.buffer'));
 
54
eq('audio/mp4', mime.lookup('file.m4a'));
 
55
eq('font/opentype', mime.lookup('file.otf'));
 
56
 
 
57
//
 
58
// Test charsets
 
59
//
 
60
 
 
61
eq('UTF-8', mime.charsets.lookup('text/plain'));
 
62
eq(undefined, mime.charsets.lookup(mime.types.js));
 
63
eq('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
 
64
 
 
65
//
 
66
// Test for overlaps between mime.types and node.types
 
67
//
 
68
 
 
69
var apacheTypes = new mime.Mime(), nodeTypes = new mime.Mime();
 
70
apacheTypes.load(path.join(__dirname, 'types/mime.types'));
 
71
nodeTypes.load(path.join(__dirname, 'types/node.types'));
 
72
 
 
73
var keys = [].concat(Object.keys(apacheTypes.types))
 
74
             .concat(Object.keys(nodeTypes.types));
 
75
keys.sort();
 
76
for (var i = 1; i < keys.length; i++) {
 
77
  if (keys[i] == keys[i-1]) {
 
78
    console.warn('Warning: ' +
 
79
      'node.types defines ' + keys[i] + '->' + nodeTypes.types[keys[i]] +
 
80
      ', mime.types defines ' + keys[i] + '->' + apacheTypes.types[keys[i]]);
 
81
  }
 
82
}
 
83
 
 
84
console.log('\nOK');