|
1 | 1 | var before = { |
2 | | - setup: function () { |
3 | | - cookies = document.cookie.split('; ') |
4 | | - for (var i = 0, c; (c = (cookies)[i]) && (c = c.split('=')[0]); i++) { |
5 | | - document.cookie = c + '=; expires=' + new Date(0).toUTCString(); |
6 | | - } |
7 | | - |
8 | | - $.cookie.defaults = {}; |
9 | | - } |
| 2 | + setup: function () { |
| 3 | + cookies = document.cookie.split('; ') |
| 4 | + for (var i = 0, c; (c = (cookies)[i]) && (c = c.split('=')[0]); i++) { |
| 5 | + document.cookie = c + '=; expires=' + new Date(0).toUTCString(); |
| 6 | + } |
| 7 | + |
| 8 | + $.cookie.defaults = {}; |
| 9 | + } |
10 | 10 | }; |
11 | 11 |
|
12 | 12 |
|
13 | 13 | module('read', before); |
14 | 14 |
|
15 | 15 | test('simple value', 1, function () { |
16 | | - document.cookie = 'c=v'; |
17 | | - equal($.cookie('c'), 'v', 'should return value'); |
| 16 | + document.cookie = 'c=v'; |
| 17 | + equal($.cookie('c'), 'v', 'should return value'); |
18 | 18 | }); |
19 | 19 |
|
20 | 20 | test('empty value', 1, function () { |
21 | | - // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, which |
22 | | - // resulted in a bug while reading such a cookie. |
23 | | - $.cookie('c', ''); |
24 | | - equal($.cookie('c'), '', 'should return value'); |
| 21 | + // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, which |
| 22 | + // resulted in a bug while reading such a cookie. |
| 23 | + $.cookie('c', ''); |
| 24 | + equal($.cookie('c'), '', 'should return value'); |
25 | 25 | }); |
26 | 26 |
|
27 | 27 | test('not existing', 1, function () { |
28 | | - equal($.cookie('whatever'), null, 'should return null'); |
| 28 | + equal($.cookie('whatever'), null, 'should return null'); |
29 | 29 | }); |
30 | 30 |
|
31 | 31 | test('decode', 1, function () { |
32 | | - document.cookie = encodeURIComponent(' c') + '=' + encodeURIComponent(' v'); |
33 | | - equal($.cookie(' c'), ' v', 'should decode key and value'); |
| 32 | + document.cookie = encodeURIComponent(' c') + '=' + encodeURIComponent(' v'); |
| 33 | + equal($.cookie(' c'), ' v', 'should decode key and value'); |
34 | 34 | }); |
35 | 35 |
|
36 | 36 | test('raw: true', 1, function () { |
37 | | - document.cookie = 'c=%20v'; |
38 | | - equal($.cookie('c', { raw: true }), '%20v', 'should not decode value'); |
| 37 | + document.cookie = 'c=%20v'; |
| 38 | + equal($.cookie('c', { raw: true }), '%20v', 'should not decode value'); |
39 | 39 | }); |
40 | 40 |
|
41 | 41 | test('[] used in name', 1, function () { |
42 | | - document.cookie = 'c[999]=foo'; |
43 | | - equal($.cookie('c[999]'), 'foo', 'should return value'); |
| 42 | + document.cookie = 'c[999]=foo'; |
| 43 | + equal($.cookie('c[999]'), 'foo', 'should return value'); |
44 | 44 | }); |
45 | 45 |
|
46 | 46 | test('embedded equals', 1, function () { |
47 | | - $.cookie('c', 'foo=bar', { raw: true }); |
48 | | - equal($.cookie('c', { raw: true }), 'foo=bar', 'should include the entire value'); |
| 47 | + $.cookie('c', 'foo=bar', { raw: true }); |
| 48 | + equal($.cookie('c', { raw: true }), 'foo=bar', 'should include the entire value'); |
49 | 49 | }); |
50 | 50 |
|
51 | 51 | test('defaults', 1, function () { |
52 | | - document.cookie = 'c=%20v'; |
53 | | - $.cookie.defaults.raw = true; |
54 | | - equal($.cookie('c'), '%20v', 'should use raw from defaults'); |
| 52 | + document.cookie = 'c=%20v'; |
| 53 | + $.cookie.defaults.raw = true; |
| 54 | + equal($.cookie('c'), '%20v', 'should use raw from defaults'); |
55 | 55 | }); |
56 | 56 |
|
57 | 57 |
|
58 | 58 | module('write', before); |
59 | 59 |
|
60 | 60 | test('String primitive', 1, function () { |
61 | | - $.cookie('c', 'v'); |
62 | | - equal($.cookie('c'), 'v', 'should write value'); |
| 61 | + $.cookie('c', 'v'); |
| 62 | + equal($.cookie('c'), 'v', 'should write value'); |
63 | 63 | }); |
64 | 64 |
|
65 | 65 | test('String object', 1, function () { |
66 | | - $.cookie('c', new String('v')); |
67 | | - equal($.cookie('c'), 'v', 'should write value'); |
| 66 | + $.cookie('c', new String('v')); |
| 67 | + equal($.cookie('c'), 'v', 'should write value'); |
68 | 68 | }); |
69 | 69 |
|
70 | 70 | test('value "[object Object]"', 1, function () { |
71 | | - $.cookie('c', '[object Object]'); |
72 | | - equal($.cookie('c'), '[object Object]', 'should write value'); |
| 71 | + $.cookie('c', '[object Object]'); |
| 72 | + equal($.cookie('c'), '[object Object]', 'should write value'); |
73 | 73 | }); |
74 | 74 |
|
75 | 75 | test('number', 1, function () { |
76 | | - $.cookie('c', 1234); |
77 | | - equal($.cookie('c'), '1234', 'should write value'); |
| 76 | + $.cookie('c', 1234); |
| 77 | + equal($.cookie('c'), '1234', 'should write value'); |
78 | 78 | }); |
79 | 79 |
|
80 | 80 | test('expires option as days from now', 1, function() { |
81 | | - var sevenDaysFromNow = new Date(); |
82 | | - sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); |
83 | | - equal($.cookie('c', 'v', { expires: 7 }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), |
84 | | - 'should write the cookie string with expires'); |
| 81 | + var sevenDaysFromNow = new Date(); |
| 82 | + sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); |
| 83 | + equal($.cookie('c', 'v', { expires: 7 }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), |
| 84 | + 'should write the cookie string with expires'); |
85 | 85 | }); |
86 | 86 |
|
87 | 87 | test('expires option as Date instance', 1, function() { |
88 | | - var sevenDaysFromNow = new Date(); |
89 | | - sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); |
90 | | - equal($.cookie('c', 'v', { expires: sevenDaysFromNow }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), |
91 | | - 'should write the cookie string with expires'); |
| 88 | + var sevenDaysFromNow = new Date(); |
| 89 | + sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); |
| 90 | + equal($.cookie('c', 'v', { expires: sevenDaysFromNow }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), |
| 91 | + 'should write the cookie string with expires'); |
92 | 92 | }); |
93 | 93 |
|
94 | 94 | test('invalid expires option (in the past)', 1, function() { |
95 | | - var yesterday = new Date(); |
96 | | - yesterday.setDate(yesterday.getDate() - 1); |
97 | | - $.cookie('c', 'v', { expires: yesterday }); |
98 | | - equal($.cookie('c'), null, 'should not save already expired cookie'); |
| 95 | + var yesterday = new Date(); |
| 96 | + yesterday.setDate(yesterday.getDate() - 1); |
| 97 | + $.cookie('c', 'v', { expires: yesterday }); |
| 98 | + equal($.cookie('c'), null, 'should not save already expired cookie'); |
99 | 99 | }); |
100 | 100 |
|
101 | 101 | test('return value', 1, function () { |
102 | | - equal($.cookie('c', 'v'), 'c=v', 'should return written cookie string'); |
| 102 | + equal($.cookie('c', 'v'), 'c=v', 'should return written cookie string'); |
103 | 103 | }); |
104 | 104 |
|
105 | 105 | test('raw option set to true', 1, function () { |
106 | | - equal($.cookie('c', ' v', { raw: true }).split('=')[1], |
107 | | - ' v', 'should not encode'); |
| 106 | + equal($.cookie('c', ' v', { raw: true }).split('=')[1], |
| 107 | + ' v', 'should not encode'); |
108 | 108 | }); |
109 | 109 |
|
110 | 110 | test('defaults', 1, function () { |
111 | | - $.cookie.defaults.raw = true; |
112 | | - equal($.cookie('c', ' v').split('=')[1], ' v', 'should use raw from defaults'); |
| 111 | + $.cookie.defaults.raw = true; |
| 112 | + equal($.cookie('c', ' v').split('=')[1], ' v', 'should use raw from defaults'); |
113 | 113 | }); |
114 | 114 |
|
115 | 115 |
|
116 | 116 | module('delete', before); |
117 | 117 |
|
118 | 118 | test('delete', 2, function () { |
119 | | - document.cookie = 'c=v'; |
120 | | - $.cookie('c', null); |
121 | | - equal(document.cookie, '', 'should delete with null as value'); |
| 119 | + document.cookie = 'c=v'; |
| 120 | + $.cookie('c', null); |
| 121 | + equal(document.cookie, '', 'should delete with null as value'); |
122 | 122 |
|
123 | | - document.cookie = 'c=v'; |
124 | | - $.cookie('c', undefined); |
125 | | - equal(document.cookie, '', 'should delete with undefined as value'); |
| 123 | + document.cookie = 'c=v'; |
| 124 | + $.cookie('c', undefined); |
| 125 | + equal(document.cookie, '', 'should delete with undefined as value'); |
126 | 126 | }); |
0 commit comments