test.js 987 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var tape = require('tape')
  2. , caseless = require('./')
  3. ;
  4. tape('set get has', function (t) {
  5. var headers = {}
  6. , c = caseless(headers)
  7. ;
  8. t.plan(17)
  9. c.set('a-Header', 'asdf')
  10. t.equal(c.get('a-header'), 'asdf')
  11. t.equal(c.has('a-header'), 'a-Header')
  12. t.ok(!c.has('nothing'))
  13. // old bug where we used the wrong regex
  14. t.ok(!c.has('a-hea'))
  15. c.set('a-header', 'fdsa')
  16. t.equal(c.get('a-header'), 'fdsa')
  17. t.equal(c.get('a-Header'), 'fdsa')
  18. c.set('a-HEADER', 'more', false)
  19. t.equal(c.get('a-header'), 'fdsa,more')
  20. t.deepEqual(headers, {'a-Header': 'fdsa,more'})
  21. c.swap('a-HEADER')
  22. t.deepEqual(headers, {'a-HEADER': 'fdsa,more'})
  23. c.set('deleteme', 'foobar')
  24. t.ok(c.has('deleteme'))
  25. t.ok(c.del('deleteme'))
  26. t.notOk(c.has('deleteme'))
  27. t.notOk(c.has('idonotexist'))
  28. t.ok(c.del('idonotexist'))
  29. c.set('tva', 'test1')
  30. c.set('tva-header', 'test2')
  31. t.equal(c.has('tva'), 'tva')
  32. t.notOk(c.has('header'))
  33. t.equal(c.get('tva'), 'test1')
  34. })