From b13b012a25f38a1dea35a5cb65b203c343b06ec1 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 3 Nov 2011 13:47:11 -0400 Subject: [PATCH] Added session storage option to store module, fixed some unit tests, improved String.trim() polyfill --- docs/files.html | 6 +- docs/index.html | 6 +- docs/symbols/$_.dom.html | 6 +- docs/symbols/$_.event.html | 6 +- docs/symbols/$_.html | 12 +- docs/symbols/$_.store.html | 128 ++++++++---- docs/symbols/$_.util.html | 6 +- docs/symbols/_global_.html | 6 +- .../src/kis-js_src_modules_store.js.html | 191 ++++++++++-------- kis-all.js | 79 +++++--- kis-min.js | 21 +- src/modules/store.js | 77 ++++--- src/polyfill.js | 2 +- tests/index.html | 50 ++++- tests/tests/core.js | 8 +- tests/tests/dom.js | 10 +- tests/tests/store.js | 118 +++++++++++ 17 files changed, 535 insertions(+), 197 deletions(-) create mode 100644 tests/tests/store.js diff --git a/docs/files.html b/docs/files.html index 4f73b2d..d5e631b 100644 --- a/docs/files.html +++ b/docs/files.html @@ -29,7 +29,7 @@
-
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
+
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
@@ -40,8 +40,8 @@
 
$_.event
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string)
-
get(string)
set(string, mixed)
remove(string)
+
+
 
$_.store
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
clear(bool)
diff --git a/docs/index.html b/docs/index.html index 6dea657..e04b915 100644 --- a/docs/index.html +++ b/docs/index.html @@ -61,7 +61,7 @@
-
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
+
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
@@ -72,8 +72,8 @@
 
$_.event
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string)
-
get(string)
set(string, mixed)
remove(string)
+
+
 
$_.store
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
clear(bool)
diff --git a/docs/symbols/$_.dom.html b/docs/symbols/$_.dom.html index 4bd848e..d25fd3b 100644 --- a/docs/symbols/$_.dom.html +++ b/docs/symbols/$_.dom.html @@ -32,7 +32,7 @@
-
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
+
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
@@ -43,8 +43,8 @@
 
$_.event
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string)
-
get(string)
set(string, mixed)
remove(string)
+
+
 
$_.store
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
clear(bool)
diff --git a/docs/symbols/$_.event.html b/docs/symbols/$_.event.html index 7788904..75f8e4c 100644 --- a/docs/symbols/$_.event.html +++ b/docs/symbols/$_.event.html @@ -32,7 +32,7 @@
-
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
+
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
@@ -43,8 +43,8 @@
 
$_.event
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string)
-
get(string)
set(string, mixed)
remove(string)
+
+
 
$_.store
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
clear(bool)
diff --git a/docs/symbols/$_.html b/docs/symbols/$_.html index 098febc..65bf9a7 100644 --- a/docs/symbols/$_.html +++ b/docs/symbols/$_.html @@ -32,7 +32,7 @@
-
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
+
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
@@ -43,8 +43,8 @@
 
$_.event
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string)
-
get(string)
set(string, mixed)
remove(string)
+
+
 
$_.store
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
clear(bool)
@@ -110,8 +110,8 @@ - store - Wrapper for localstorage data serialization + store + Wrapper for localstorage / sessionstorage data serialization
@@ -244,7 +244,7 @@ Dom manipulation module
- Wrapper for localstorage data serialization + Wrapper for localstorage / sessionstorage data serialization

Defined in: store.js.

diff --git a/docs/symbols/$_.store.html b/docs/symbols/$_.store.html index a0b7d06..15bc7b3 100644 --- a/docs/symbols/$_.store.html +++ b/docs/symbols/$_.store.html @@ -32,7 +32,7 @@
-
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
+
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
@@ -43,8 +43,8 @@
 
$_.event
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string)
-
get(string)
set(string, mixed)
remove(string)
+
+
 
$_.store
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
clear(bool)
@@ -105,7 +105,7 @@ - get(string) + get(string, bool) Retrieves and deserializes a value from localstorage, based on the specified key
@@ -113,7 +113,7 @@ - set(string, mixed) + set(string, mixed, bool) Puts a value into localstorage at the specified key, and JSON-encodes the value if not a string
@@ -121,8 +121,16 @@ - remove(string) - Removes the specified item from localstorage + remove(string, bool) + Removes the specified item from storage + + +
+ + clear(bool) + Removes all values from the same domain storage
@@ -148,8 +156,8 @@
- $_.store.get(string) - + $_.store.get(string, bool) + : object
Retrieves and deserializes a value from localstorage, @@ -178,6 +186,18 @@ based on the specified key + + + + + + bool + + + session + + + @@ -207,7 +227,7 @@ based on the specified key
- $_.store.set(string, mixed) + $_.store.set(string, mixed, bool)
@@ -249,21 +269,15 @@ and JSON-encodes the value if not a string - - - - - - -
Returns:
- - + @@ -271,6 +285,10 @@ and JSON-encodes the value if not a string + + + + @@ -278,11 +296,11 @@ and JSON-encodes the value if not a string
- $_.store.remove(string) + $_.store.remove(string, bool)
- Removes the specified item from localstorage + Removes the specified item from storage @@ -307,21 +325,15 @@ and JSON-encodes the value if not a string -
- + + + bool - void + session
- - - - - -
Returns:
- - + @@ -329,6 +341,54 @@ and JSON-encodes the value if not a string + + + + + + + + +
+ +
+ $_.store.clear(bool) + +
+
+ Removes all values from the same domain storage + + + + +

+										
+									
+ + +
Parameters:
+
- + + + bool - void + session
+ + + + + + + +
+ + + bool + + session +
+ + + + + + +
diff --git a/docs/symbols/$_.util.html b/docs/symbols/$_.util.html index ad285a3..36180e2 100644 --- a/docs/symbols/$_.util.html +++ b/docs/symbols/$_.util.html @@ -32,7 +32,7 @@
-
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
+
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
@@ -43,8 +43,8 @@
 
$_.event
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string)
-
get(string)
set(string, mixed)
remove(string)
+
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
clear(bool)
diff --git a/docs/symbols/_global_.html b/docs/symbols/_global_.html index c00fed7..2ec1c96 100644 --- a/docs/symbols/_global_.html +++ b/docs/symbols/_global_.html @@ -32,7 +32,7 @@
-
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
+
 
$_
$(string, string)
ext(string, object)
each(function)
type(mixed)
get(string, object, function)
post(string, object, function)
@@ -43,8 +43,8 @@
 
$_.event
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string)
-
get(string)
set(string, mixed)
remove(string)
+
+
 
$_.store
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
clear(bool)
diff --git a/docs/symbols/src/kis-js_src_modules_store.js.html b/docs/symbols/src/kis-js_src_modules_store.js.html index 8778919..8ed3ef5 100755 --- a/docs/symbols/src/kis-js_src_modules_store.js.html +++ b/docs/symbols/src/kis-js_src_modules_store.js.html @@ -7,88 +7,117 @@ .line {border-right: 1px dotted #666; color: #666; font-style: normal;}
  1 (function (){
   2 	"use strict";
-  3 
-  4 	/**
-  5 	 * Wrapper for localstorage data serialization
-  6 	 *
-  7 	 * @name store
-  8 	 * @namespace
-  9 	 * @memberOf $_
- 10 	 */
- 11 	var store = {
- 12 		/**
- 13 		 * Retrieves and deserializes a value from localstorage, 
- 14 		 * based on the specified key
- 15 		 * 
- 16 		 * @param string key
- 17 		 * @name get
- 18 		 * @memberOf $_.store
- 19 		 * @function
- 20 		 * @return object
- 21 		 */
- 22 		get: function (key)
- 23 		{
- 24 			return JSON.parse(localStorage.getItem(key));
- 25 		},
- 26 		/**
- 27 		 * Puts a value into localstorage at the specified key,
- 28 		 * and JSON-encodes the value if not a string
- 29 		 *
- 30 		 * @param string key
- 31 		 * @param mixed value
- 32 		 * @name set
- 33 		 * @memberOf $_.store
- 34 		 * @function
- 35 		 * @return void
- 36 		 */
- 37 		set: function (key, value)
- 38 		{
- 39 			if (typeof value !== "string")
- 40 			{
- 41 				value = JSON.stringify(value);
- 42 			}
- 43 			localStorage.setItem(key, value);
- 44 		},
- 45 		/**
- 46 		 * Removes the specified item from localstorage
- 47 		 * 
- 48 		 * @param string key
- 49 		 * @name remove
- 50 		 * @memberOf $_.store
- 51 		 * @function
- 52 		 * @return void 
- 53 		 */
- 54 		remove: function (key)
- 55 		{
- 56 			localStorage.removeItem(key);
+  3 	
+  4 	//No support for localstorage? Bail out early
+  5 	if(typeof localStorage === "undefined" || typeof JSON === "undefined")
+  6 	{
+  7 		return;
+  8 	}
+  9 	
+ 10 	//Shortcuts for wrapper
+ 11 	var l = localStorage,
+ 12 		s = sessionStorage;
+ 13 
+ 14 	/**
+ 15 	 * Wrapper for localstorage / sessionstorage data serialization
+ 16 	 *
+ 17 	 * @name store
+ 18 	 * @namespace
+ 19 	 * @memberOf $_
+ 20 	 */
+ 21 	var store = {		
+ 22 		/**
+ 23 		 * Retrieves and deserializes a value from localstorage, 
+ 24 		 * based on the specified key
+ 25 		 * 
+ 26 		 * @param string key
+ 27 		 * @param bool session
+ 28 		 * @name get
+ 29 		 * @memberOf $_.store
+ 30 		 * @function
+ 31 		 * @return object
+ 32 		 * @type object
+ 33 		 */
+ 34 		get: function (key, sess)
+ 35 		{
+ 36 			var val = (sess) ? s.getItem(key) : l.getItem(key);
+ 37 		
+ 38 			return JSON.parse(val);
+ 39 		},
+ 40 		/**
+ 41 		 * Puts a value into localstorage at the specified key,
+ 42 		 * and JSON-encodes the value if not a string
+ 43 		 *
+ 44 		 * @param string key
+ 45 		 * @param mixed value
+ 46 		 * @param bool session
+ 47 		 * @name set
+ 48 		 * @memberOf $_.store
+ 49 		 * @function
+ 50 		 */
+ 51 		set: function (key, value, sess)
+ 52 		{
+ 53 			// Localstorage generally only accepts strings
+ 54 			value = JSON.stringify(value);			
+ 55 			
+ 56 			(sess) ? s.setItem(key, value) : l.setItem(key, value);
  57 		},
  58 		/**
- 59 		 * Returns an array of all the values in localstorage
- 60 		 * in their raw form
- 61 		 * 
- 62 		 * @name getAll
- 63 		 * @member of $_.store
- 64 		 * @function
- 65 		 * @return object
+ 59 		 * Removes the specified item from storage
+ 60 		 * 
+ 61 		 * @param string key
+ 62 		 * @param bool session
+ 63 		 * @name remove
+ 64 		 * @memberOf $_.store
+ 65 		 * @function
  66 		 */
- 67 		getAll: function ()
+ 67 		remove: function (key, sess)
  68 		{
- 69 			var i,
- 70 				len,
- 71 				data;
- 72 			len = localStorage.length;
- 73 			data = {};
- 74 
- 75 			for (i = 0; i < len; i++)
- 76 			{
- 77 				var name = localStorage.key(i);
- 78 				var value = localStorage.getItem(name);
- 79 				data[name] = value;
- 80 			}
- 81 
- 82 			return data;
- 83 		}
- 84 	};
- 85 
- 86 	$_.ext('store', store);
- 87 }());
\ No newline at end of file + 69 (sess) ? s.removeItem(key) : l.removeItem(key); + 70 }, + 71 /** + 72 * Removes all values from the same domain storage + 73 * + 74 * @param bool session + 75 * @name clear + 76 * @memberOf $_.store + 77 * @function + 78 */ + 79 clear: function(sess) + 80 { + 81 (sess) ? s.clear() : l.clear(); + 82 }, + 83 /** + 84 * Returns an object of all the raw values in storage + 85 * + 86 * @name getAll + 87 * @member of $_.store + 88 * @function + 89 * @return object + 90 * @type object + 91 */ + 92 getAll: function (sess) + 93 { + 94 var i, + 95 len, + 96 data = {}, + 97 k, + 98 o; + 99 +100 //Reference to session/localstorage +101 o = (sess) ? l : s; +102 +103 len = o.length; +104 +105 for (i = 0; i < len; i++) +106 { +107 k = o.key(i); +108 data[k] = o.getItem(k); +109 } +110 +111 return data; +112 } +113 }; +114 +115 $_.ext('store', store); +116 }()); \ No newline at end of file diff --git a/kis-all.js b/kis-all.js index 6601309..8ce0b9b 100644 --- a/kis-all.js +++ b/kis-all.js @@ -239,7 +239,7 @@ if(typeof String.prototype.trim === "undefined") * @private */ String.prototype.trim = function(){ - return this.replace(/^\s+|\s+$/g, ""); + return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, ""); }; } @@ -758,28 +758,42 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" (function (){ "use strict"; + + //No support for localstorage? Bail out early + if(typeof localStorage === "undefined" || typeof JSON === "undefined") + { + return; + } + + //Shortcuts for wrapper + var l = localStorage, + s = sessionStorage; /** - * Wrapper for localstorage data serialization + * Wrapper for localstorage / sessionstorage data serialization * * @name store * @namespace * @memberOf $_ */ - var store = { + var store = { /** * Retrieves and deserializes a value from localstorage, * based on the specified key * * @param string key + * @param bool session * @name get * @memberOf $_.store * @function * @return object + * @type object */ - get: function (key) + get: function (key, sess) { - return JSON.parse(localStorage.getItem(key)); + var val = (sess) ? s.getItem(key) : l.getItem(key); + + return JSON.parse(val); }, /** * Puts a value into localstorage at the specified key, @@ -787,54 +801,69 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" * * @param string key * @param mixed value + * @param bool session * @name set * @memberOf $_.store * @function - * @return void */ - set: function (key, value) + set: function (key, value, sess) { - if (typeof value !== "string") - { - value = JSON.stringify(value); - } - localStorage.setItem(key, value); + // Localstorage generally only accepts strings + value = JSON.stringify(value); + + (sess) ? s.setItem(key, value) : l.setItem(key, value); }, /** - * Removes the specified item from localstorage + * Removes the specified item from storage * * @param string key + * @param bool session * @name remove * @memberOf $_.store * @function - * @return void */ - remove: function (key) + remove: function (key, sess) { - localStorage.removeItem(key); + (sess) ? s.removeItem(key) : l.removeItem(key); }, /** - * Returns an array of all the values in localstorage - * in their raw form + * Removes all values from the same domain storage + * + * @param bool session + * @name clear + * @memberOf $_.store + * @function + */ + clear: function(sess) + { + (sess) ? s.clear() : l.clear(); + }, + /** + * Returns an object of all the raw values in storage * * @name getAll * @member of $_.store * @function * @return object + * @type object */ - getAll: function () + getAll: function (sess) { var i, len, - data; - len = localStorage.length; - data = {}; + data = {}, + k, + o; + + //Reference to session/localstorage + o = (sess) ? l : s; + + len = o.length; for (i = 0; i < len; i++) { - var name = localStorage.key(i); - var value = localStorage.getItem(name); - data[name] = value; + k = o.key(i); + data[k] = o.getItem(k); } return data; diff --git a/kis-min.js b/kis-min.js index eb85d14..ff1ec48 100644 --- a/kis-min.js +++ b/kis-min.js @@ -1 +1,20 @@ -(function(){if(typeof document.querySelector!=="undefined"){var d,h,f,b;d=function(a){b=typeof a==="undefined"?typeof d.el!=="undefined"?d.el:document.documentElement:typeof a!=="object"?h(a):a;d.prototype.el=b;var a=f(d),c;for(c in a)if(typeof a[c]==="object")a[c].el=b;a.el=b;return a};h=function(a,c){var b;if(typeof a!="string"||typeof a==="undefined")return a;b=c!=null&&c.nodeType===1?c:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);else b=b.querySelectorAll(a); return b.length===1?b[0]:b};f=function(a){var c;if(typeof a!=="undefined"){if(typeof Object.create!=="undefined")return Object.create(a);c=typeof a;if(!(c!=="object"&&c!=="function"))return c=function(){},c.prototype=a,new c}};d.ext=function(a,c){c.el=b;d[a]=c};d.ext("each",function(a){if(typeof b.length!=="undefined"&&b!==window){var c=b.length;if(c!==0)for(var e,g=0;g1&&typeof a==="undefined")console.log(c),console.log("Must be a singular element");else if(c.length>1&&typeof a!== "undefined")$_.each(function(c){return d(c,b,a)});else return d(c,b,a)},text:function(b){var a,c,e;e=this.el;c=typeof e.innerText!=="undefined"?"innerText":typeof e.textContent!=="undefined"?"textContent":"innerHTML";a=e[c];return typeof b!=="undefined"?e[c]=b:a},css:function(b,a){if(typeof a==="undefined")return f(this.el,b);$_.each(function(c){f(c,b,a)})},html:function(b){if(typeof b!=="undefined")this.el.innerHTML=b;return this.el.innerHTML}})})(); (function(){$_.ext("store",{get:function(d){return JSON.parse(localStorage.getItem(d))},set:function(d,h){typeof h!=="string"&&(h=JSON.stringify(h));localStorage.setItem(d,h)},remove:function(d){localStorage.removeItem(d)},getAll:function(){var d,h,f;h=localStorage.length;f={};for(d=0;de?1:ba?1:c1&&typeof a==="undefined")console.log(c),console.log("Must be a singular element");else if(c.length>1&&typeof a!== +"undefined")$_.each(function(c){return f(c,b,a)});else return f(c,b,a)},text:function(b){var a,c,e;e=this.el;c=typeof e.innerText!=="undefined"?"innerText":typeof e.textContent!=="undefined"?"textContent":"innerHTML";a=e[c];return typeof b!=="undefined"?e[c]=b:a},css:function(b,a){if(typeof a==="undefined")return d(this.el,b);$_.each(function(c){d(c,b,a)})},html:function(b){if(typeof b!=="undefined")this.el.innerHTML=b;return this.el.innerHTML}})})(); +(function(){if(!(typeof localStorage==="undefined"||typeof JSON==="undefined")){var f=localStorage,g=sessionStorage;$_.ext("store",{get:function(d,b){var a=b?g.getItem(d):f.getItem(d);return JSON.parse(a)},set:function(d,b,a){b=JSON.stringify(b);a?g.setItem(d,b):f.setItem(d,b)},remove:function(d,b){b?g.removeItem(d):f.removeItem(d)},clear:function(d){d?g.clear():f.clear()},getAll:function(d){var b,a={},c,e;e=d?f:g;b=e.length;for(d=0;de?1:ba?1:c
- + + \ No newline at end of file diff --git a/tests/tests/core.js b/tests/tests/core.js index af48563..2fe54e7 100644 --- a/tests/tests/core.js +++ b/tests/tests/core.js @@ -5,11 +5,13 @@ module("core"); test("Basic requirements", function(){ - expect(6); + expect(8); ok(document.querySelectorAll, "querySelectorAll"); ok(document.getElementById, "getElementById"); ok(document.getElementsByTagName, "getElementsByTagName"); ok(String.prototype.trim, "String.trim()"); + ok(JSON.parse, "JSON.parse()"); + ok(JSON.stringify, "JSON.stringify()"); strictEqual(typeof $_, "function", "Global var"); strictEqual(typeof $_(), "object"); }); @@ -36,8 +38,8 @@ $_.ext('test', {}); strictEqual(typeof o.test, "object", "Extend function adds to $_"); - strictEqual(o.test.el, $_("ol").el, "Extend function adds selector to passed object"); - strictEqual(o.test.el, o.el, "Selector is the same on parent and child object"); + strictEqual(is_clone(o.test.el, $_("ol").el), true, "Extend function adds selector to passed object"); + strictEqual(is_clone(o.test.el, o.el), true, "Selector is the same on parent and child object"); o = null; }); diff --git a/tests/tests/dom.js b/tests/tests/dom.js index e3d7542..15a5025 100644 --- a/tests/tests/dom.js +++ b/tests/tests/dom.js @@ -79,10 +79,14 @@ test("html", function(){ expect(2); - var test_html = 'Send Tim an email'; + var orig_html = "This is important text!"; + var test_html = 'send tim an email'; - equal($_('#r14').dom.html().trim(), "This is important text!".trim(), "Gets html"); - equal($_('#r14').dom.html(test_html), test_html, "Sets html"); + document.getElementById('r14').innerHTML = orig_html; + + + equal($_('#r14').dom.html().trim(), "This is important text!", "Gets html"); + equal($_('#r14').dom.html(test_html).toLowerCase(), test_html, "Sets html"); }); }()); \ No newline at end of file diff --git a/tests/tests/store.js b/tests/tests/store.js new file mode 100644 index 0000000..efa2961 --- /dev/null +++ b/tests/tests/store.js @@ -0,0 +1,118 @@ +(function (){ + //"use strict"; + + module("store"); + + //Test data + var test_obj = { + test:'value', + t:3, + x:[0,5,3] + }; + var t = JSON.stringify(test_obj); + + test("Clear", function(){ + expect(2); + + //Setup + localStorage.clear(); + localStorage.setItem("test", "value"); + + sessionStorage.clear(); + sessionStorage.setItem("test", "value"); + + //Clear localStorage + $_.store.clear(); + equal(localStorage.length, 0, "No items in localStorage"); + + //Clear sessionStorage + $_.store.clear(true); + equal(sessionStorage.length, 0, "No items in sessionStorage"); + + }); + + test("Set", function(){ + expect(2); + + $_.store.set('test', test_obj); + strictEqual(localStorage.getItem('test'), t, "Set object in localStorage"); + + $_.store.set('test', test_obj, true); + strictEqual(sessionStorage.getItem('test'), t, "Set object in sessionStorage"); + + }); + + test("Get", function(){ + expect(2); + + //Test data + var test_obj = { + test:'value', + t:3, + x:[0,5,3] + }; + var t = JSON.stringify(test_obj); + var t_prime = JSON.parse(t); + + //This is tricky because test_obj != JSON.parse(JSON.stringify(test_obj)) + + + equal(JSON.stringify($_.store.get('test')), t, "Gets and parses object from localStorage"); + equal(JSON.stringify($_.store.get('test', true)), t, "Gets and parses object from localStorage"); + + }); + + test("Remove", function(){ + expect(2); + + $_.store.remove('test'); + equal(localStorage["test"], null, "Removes from localStorage"); + + $_.store.remove('test', true); + equal(sessionStorage["test"], null, "Removes from sessionStorage"); + }); + + test("Get All", function(){ + expect(2); + + //Make sure storage is clean + localStorage.clear(); + sessionStorage.clear(); + + var foo = { + a: [0,5,6] + }; + + var bar = { + x: { + b: 2 + }, + y: "baz" + }; + + var comb = { + foo: JSON.stringify(foo), + bar: JSON.stringify(bar), + q: "What is the question?" + }; + + $_.store.set('foo', foo); + $_.store.set('bar', bar); + localStorage.setItem('q', "What is the question?"); + + $_.store.set('foo', foo, true); + $_.store.set('bar', bar, true); + sessionStorage.setItem('q', "What is the question?"); + + var all_local = $_.store.getAll(); + var all_session = $_.store.getAll(true); + + + + //comb = comb; + + equal(is_clone(all_local, comb), true, "Gets all items from localStorage"); + equal(is_clone(all_session, comb), true, "Gets all items from sessionStorage"); + }); + +}()); \ No newline at end of file