test-utils-decoder.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. var Decoder = require('../lib/utils').Decoder;
  2. var path = require('path'),
  3. assert = require('assert');
  4. var group = path.basename(__filename, '.js') + '/';
  5. [
  6. { source: ['Hello world'],
  7. expected: 'Hello world',
  8. what: 'No encoded bytes'
  9. },
  10. { source: ['Hello%20world'],
  11. expected: 'Hello world',
  12. what: 'One full encoded byte'
  13. },
  14. { source: ['Hello%20world%21'],
  15. expected: 'Hello world!',
  16. what: 'Two full encoded bytes'
  17. },
  18. { source: ['Hello%', '20world'],
  19. expected: 'Hello world',
  20. what: 'One full encoded byte split #1'
  21. },
  22. { source: ['Hello%2', '0world'],
  23. expected: 'Hello world',
  24. what: 'One full encoded byte split #2'
  25. },
  26. { source: ['Hello%20', 'world'],
  27. expected: 'Hello world',
  28. what: 'One full encoded byte (concat)'
  29. },
  30. { source: ['Hello%2Qworld'],
  31. expected: 'Hello%2Qworld',
  32. what: 'Malformed encoded byte #1'
  33. },
  34. { source: ['Hello%world'],
  35. expected: 'Hello%world',
  36. what: 'Malformed encoded byte #2'
  37. },
  38. { source: ['Hello+world'],
  39. expected: 'Hello world',
  40. what: 'Plus to space'
  41. },
  42. { source: ['Hello+world%21'],
  43. expected: 'Hello world!',
  44. what: 'Plus and encoded byte'
  45. },
  46. { source: ['5%2B5%3D10'],
  47. expected: '5+5=10',
  48. what: 'Encoded plus'
  49. },
  50. { source: ['5+%2B+5+%3D+10'],
  51. expected: '5 + 5 = 10',
  52. what: 'Spaces and encoded plus'
  53. },
  54. ].forEach(function(v) {
  55. var dec = new Decoder(), result = '';
  56. v.source.forEach(function(s) {
  57. result += dec.write(s);
  58. });
  59. var msg = '[' + group + v.what + ']: decoded string mismatch.\n'
  60. + 'Saw: ' + result + '\n'
  61. + 'Expected: ' + v.expected;
  62. assert.deepEqual(result, v.expected, msg);
  63. });