twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

test.js (1585B)


      1 var tape = require('tape')
      2   , caseless = require('./')
      3   ;
      4 
      5 tape('set get has', function (t) {
      6   var headers = {}
      7     , c = caseless(headers)
      8     ;
      9   t.plan(17)
     10   c.set('a-Header', 'asdf')
     11   t.equal(c.get('a-header'), 'asdf')
     12   t.equal(c.has('a-header'), 'a-Header')
     13   t.ok(!c.has('nothing'))
     14   // old bug where we used the wrong regex
     15   t.ok(!c.has('a-hea'))
     16   c.set('a-header', 'fdsa')
     17   t.equal(c.get('a-header'), 'fdsa')
     18   t.equal(c.get('a-Header'), 'fdsa')
     19   c.set('a-HEADER', 'more', false)
     20   t.equal(c.get('a-header'), 'fdsa,more')
     21 
     22   t.deepEqual(headers, {'a-Header': 'fdsa,more'})
     23   c.swap('a-HEADER')
     24   t.deepEqual(headers, {'a-HEADER': 'fdsa,more'})
     25 
     26   c.set('deleteme', 'foobar')
     27   t.ok(c.has('deleteme'))
     28   t.ok(c.del('deleteme'))
     29   t.notOk(c.has('deleteme'))
     30   t.notOk(c.has('idonotexist'))
     31   t.ok(c.del('idonotexist'))
     32 
     33   c.set('tva', 'test1')
     34   c.set('tva-header', 'test2')
     35   t.equal(c.has('tva'), 'tva')
     36   t.notOk(c.has('header'))
     37 
     38   t.equal(c.get('tva'), 'test1')
     39 
     40 })
     41 
     42 tape('swap', function (t) {
     43   var headers = {}
     44     , c = caseless(headers)
     45     ;
     46   t.plan(4)
     47   // No Header to Swap.
     48   t.throws(function () {
     49     c.swap('content-type')
     50   })
     51   // Set Header.
     52   c.set('content-type', 'application/json')
     53   // Swap Header With Itself.
     54   c.swap('content-type')
     55   // Does Not Delete Itself.
     56   t.ok(c.has('content-type'))
     57   // Swap Header With a Different Header.
     58   c.swap('Content-Type')
     59   // Still Has Header.
     60   t.ok(c.has('Content-Type'))
     61   // Delete Header.
     62   c.del('Content-Type')
     63   // No Header to Swap.
     64   t.throws(function () {
     65     c.swap('content-type')
     66   })
     67 })