source: trip-planner-front/node_modules/caseless/test.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1var tape = require('tape')
2 , caseless = require('./')
3 ;
4
5tape('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
42tape('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})
Note: See TracBrowser for help on using the repository browser.