twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

test.js (2334B)


      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 //
     10 // Test mime lookups
     11 //
     12 
     13 assert.equal('text/plain', mime.lookup('text.txt'));     // normal file
     14 assert.equal('text/plain', mime.lookup('TEXT.TXT'));     // uppercase
     15 assert.equal('text/plain', mime.lookup('dir/text.txt')); // dir + file
     16 assert.equal('text/plain', mime.lookup('.text.txt'));    // hidden file
     17 assert.equal('text/plain', mime.lookup('.txt'));         // nameless
     18 assert.equal('text/plain', mime.lookup('txt'));          // extension-only
     19 assert.equal('text/plain', mime.lookup('/txt'));         // extension-less ()
     20 assert.equal('text/plain', mime.lookup('\\txt'));        // Windows, extension-less
     21 assert.equal('application/octet-stream', mime.lookup('text.nope')); // unrecognized
     22 assert.equal('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
     23 
     24 //
     25 // Test extensions
     26 //
     27 
     28 assert.equal('txt', mime.extension(mime.types.text));
     29 assert.equal('html', mime.extension(mime.types.htm));
     30 assert.equal('bin', mime.extension('application/octet-stream'));
     31 assert.equal('bin', mime.extension('application/octet-stream '));
     32 assert.equal('html', mime.extension(' text/html; charset=UTF-8'));
     33 assert.equal('html', mime.extension('text/html; charset=UTF-8 '));
     34 assert.equal('html', mime.extension('text/html; charset=UTF-8'));
     35 assert.equal('html', mime.extension('text/html ; charset=UTF-8'));
     36 assert.equal('html', mime.extension('text/html;charset=UTF-8'));
     37 assert.equal('html', mime.extension('text/Html;charset=UTF-8'));
     38 assert.equal(undefined, mime.extension('unrecognized'));
     39 
     40 //
     41 // Test node.types lookups
     42 //
     43 
     44 assert.equal('font/woff', mime.lookup('file.woff'));
     45 assert.equal('application/octet-stream', mime.lookup('file.buffer'));
     46 // TODO: Uncomment once #157 is resolved
     47 // assert.equal('audio/mp4', mime.lookup('file.m4a'));
     48 assert.equal('font/otf', mime.lookup('file.otf'));
     49 
     50 //
     51 // Test charsets
     52 //
     53 
     54 assert.equal('UTF-8', mime.charsets.lookup('text/plain'));
     55 assert.equal('UTF-8', mime.charsets.lookup(mime.types.js));
     56 assert.equal('UTF-8', mime.charsets.lookup(mime.types.json));
     57 assert.equal(undefined, mime.charsets.lookup(mime.types.bin));
     58 assert.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
     59 
     60 console.log('\nAll tests passed');