test.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var test = require('tape')
  2. , parse = require('./parse-headers')
  3. , headers1 = [
  4. ''
  5. , 'Date: Sun, 17 Aug 2014 16:24:52 GMT'
  6. , 'Content-Type: text/html; charset=utf-8'
  7. , 'Transfer-Encoding: chunked'
  8. , ''
  9. ]
  10. , headers2 = [
  11. ''
  12. , 'Date: Sun, 17 Aug 2014 16:24:52 GMT'
  13. , 'Content-Type: text/html; charset=utf-8'
  14. , 'Transfer-Encoding: chunked'
  15. , 'Set-Cookie: Foo'
  16. , 'set-Cookie: bar'
  17. , 'set-cookie: bong'
  18. ]
  19. test('sanity check', function (t) {
  20. t.deepEqual(parse(), {})
  21. t.deepEqual(parse(''), {})
  22. t.end()
  23. })
  24. test('simple', function (t) {
  25. t.deepEqual(
  26. parse(headers1.join('\r\n'))
  27. , {
  28. date: 'Sun, 17 Aug 2014 16:24:52 GMT'
  29. , 'content-type': 'text/html; charset=utf-8'
  30. , 'transfer-encoding': 'chunked'
  31. }
  32. )
  33. t.deepEqual(
  34. parse(headers1.join('\n'))
  35. , {
  36. date: 'Sun, 17 Aug 2014 16:24:52 GMT'
  37. , 'content-type': 'text/html; charset=utf-8'
  38. , 'transfer-encoding': 'chunked'
  39. }
  40. )
  41. t.end()
  42. })
  43. test('duplicate keys', function (t) {
  44. t.deepEqual(
  45. parse(headers2.join('\r\n'))
  46. , {
  47. date: 'Sun, 17 Aug 2014 16:24:52 GMT'
  48. , 'content-type': 'text/html; charset=utf-8'
  49. , 'transfer-encoding': 'chunked'
  50. , 'set-cookie': [ 'Foo', 'bar', 'bong' ]
  51. }
  52. )
  53. t.deepEqual(
  54. parse(headers2.join('\n'))
  55. , {
  56. date: 'Sun, 17 Aug 2014 16:24:52 GMT'
  57. , 'content-type': 'text/html; charset=utf-8'
  58. , 'transfer-encoding': 'chunked'
  59. , 'set-cookie': [ 'Foo', 'bar', 'bong' ]
  60. }
  61. )
  62. t.end()
  63. })