Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Usage: node test.js
  3. */
  4. var mime = require('../mime');
  5. var assert = require('assert');
  6. var path = require('path');
  7. //
  8. // Test mime lookups
  9. //
  10. assert.equal('text/plain', mime.lookup('text.txt')); // normal file
  11. assert.equal('text/plain', mime.lookup('TEXT.TXT')); // uppercase
  12. assert.equal('text/plain', mime.lookup('dir/text.txt')); // dir + file
  13. assert.equal('text/plain', mime.lookup('.text.txt')); // hidden file
  14. assert.equal('text/plain', mime.lookup('.txt')); // nameless
  15. assert.equal('text/plain', mime.lookup('txt')); // extension-only
  16. assert.equal('text/plain', mime.lookup('/txt')); // extension-less ()
  17. assert.equal('text/plain', mime.lookup('\\txt')); // Windows, extension-less
  18. assert.equal('application/octet-stream', mime.lookup('text.nope')); // unrecognized
  19. assert.equal('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
  20. //
  21. // Test extensions
  22. //
  23. assert.equal('txt', mime.extension(mime.types.text));
  24. assert.equal('html', mime.extension(mime.types.htm));
  25. assert.equal('bin', mime.extension('application/octet-stream'));
  26. assert.equal('bin', mime.extension('application/octet-stream '));
  27. assert.equal('html', mime.extension(' text/html; charset=UTF-8'));
  28. assert.equal('html', mime.extension('text/html; charset=UTF-8 '));
  29. assert.equal('html', mime.extension('text/html; charset=UTF-8'));
  30. assert.equal('html', mime.extension('text/html ; charset=UTF-8'));
  31. assert.equal('html', mime.extension('text/html;charset=UTF-8'));
  32. assert.equal('html', mime.extension('text/Html;charset=UTF-8'));
  33. assert.equal(undefined, mime.extension('unrecognized'));
  34. //
  35. // Test node.types lookups
  36. //
  37. assert.equal('font/woff', mime.lookup('file.woff'));
  38. assert.equal('application/octet-stream', mime.lookup('file.buffer'));
  39. // TODO: Uncomment once #157 is resolved
  40. // assert.equal('audio/mp4', mime.lookup('file.m4a'));
  41. assert.equal('font/otf', mime.lookup('file.otf'));
  42. //
  43. // Test charsets
  44. //
  45. assert.equal('UTF-8', mime.charsets.lookup('text/plain'));
  46. assert.equal('UTF-8', mime.charsets.lookup(mime.types.js));
  47. assert.equal('UTF-8', mime.charsets.lookup(mime.types.json));
  48. assert.equal(undefined, mime.charsets.lookup(mime.types.bin));
  49. assert.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
  50. console.log('\nAll tests passed');