2011-07-22 19:21:23 +00:00
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var assert = require('assert')
|
2012-08-16 19:18:48 +00:00
|
|
|
, localStorage = require('localStorage')
|
2011-07-22 19:21:23 +00:00
|
|
|
;
|
|
|
|
|
2013-01-26 04:12:55 +00:00
|
|
|
// don't return prototypical things
|
|
|
|
assert.strictEqual(localStorage.getItem('key'), null);
|
|
|
|
|
2012-08-16 19:18:48 +00:00
|
|
|
// can't make assuptions about key positioning
|
|
|
|
localStorage.setItem('a', 1);
|
|
|
|
assert.strictEqual(localStorage.key(0), 'a');
|
2011-07-22 19:21:23 +00:00
|
|
|
|
2012-08-16 19:18:48 +00:00
|
|
|
localStorage.setItem('b', '2');
|
|
|
|
assert.strictEqual(localStorage.getItem('a'), '1');
|
|
|
|
assert.strictEqual(localStorage.getItem('b'), '2');
|
|
|
|
assert.strictEqual(localStorage.length, 2);
|
2011-07-22 19:21:23 +00:00
|
|
|
|
2012-08-16 19:18:48 +00:00
|
|
|
assert.strictEqual(localStorage['c'], undefined);
|
|
|
|
assert.strictEqual(localStorage.getItem('c'), null);
|
2011-07-22 19:21:23 +00:00
|
|
|
|
2012-08-16 19:18:48 +00:00
|
|
|
localStorage.setItem('c');
|
|
|
|
assert.strictEqual(localStorage.getItem('c'), "undefined");
|
|
|
|
assert.strictEqual(localStorage.length, 3);
|
2011-07-22 19:21:23 +00:00
|
|
|
|
2012-08-16 19:18:48 +00:00
|
|
|
localStorage.removeItem('c');
|
|
|
|
assert.strictEqual(localStorage.getItem('c'), null);
|
|
|
|
assert.strictEqual(localStorage.length, 2);
|
2011-07-22 19:21:23 +00:00
|
|
|
|
2012-08-16 19:18:48 +00:00
|
|
|
localStorage.clear();
|
|
|
|
assert.strictEqual(localStorage.getItem('a'), null);
|
|
|
|
assert.strictEqual(localStorage.getItem('b'), null);
|
|
|
|
assert.strictEqual(localStorage.length, 0);
|
2011-07-22 19:21:23 +00:00
|
|
|
|
2012-08-16 19:18:48 +00:00
|
|
|
console.log('All tests passed');
|
2011-07-22 19:21:23 +00:00
|
|
|
}());
|