charset.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. (function() {
  2. var configuration, preferredCharsets, testConfigurations, testCorrectCharset, _i, _len,
  3. _this = this;
  4. preferredCharsets = require('../lib/charset').preferredCharsets;
  5. this["Should not return a charset when no charset is provided"] = function(test) {
  6. test.deepEqual(preferredCharsets('*', []), []);
  7. return test.done();
  8. };
  9. this["Should not return a charset when no charset is acceptable"] = function(test) {
  10. test.deepEqual(preferredCharsets('ISO-8859-1', ['utf-8']), []);
  11. return test.done();
  12. };
  13. this["Should not return a charset with q = 0"] = function(test) {
  14. test.deepEqual(preferredCharsets('utf-8;q=0', ['utf-8']), []);
  15. return test.done();
  16. };
  17. testCorrectCharset = function(c) {
  18. return _this["Should return " + c.selected + " for accept-charset header " + c.accept + " with provided charset " + c.provided] = function(test) {
  19. test.deepEqual(preferredCharsets(c.accept, c.provided), c.selected);
  20. return test.done();
  21. };
  22. };
  23. testConfigurations = [
  24. {
  25. accept: 'utf-8',
  26. provided: ['utf-8'],
  27. selected: ['utf-8']
  28. }, {
  29. accept: '*',
  30. provided: ['utf-8'],
  31. selected: ['utf-8']
  32. }, {
  33. accept: 'utf-8',
  34. provided: ['utf-8', 'ISO-8859-1'],
  35. selected: ['utf-8']
  36. }, {
  37. accept: 'utf-8, ISO-8859-1',
  38. provided: ['utf-8'],
  39. selected: ['utf-8']
  40. }, {
  41. accept: 'utf-8;q=0.8, ISO-8859-1',
  42. provided: ['utf-8', 'ISO-8859-1'],
  43. selected: ['ISO-8859-1', 'utf-8']
  44. }, {
  45. accept: 'utf-8;q=0.8, ISO-8859-1',
  46. provided: null,
  47. selected: ['ISO-8859-1', 'utf-8']
  48. }
  49. ];
  50. for (_i = 0, _len = testConfigurations.length; _i < _len; _i++) {
  51. configuration = testConfigurations[_i];
  52. testCorrectCharset(configuration);
  53. }
  54. }).call(this);