Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added browser tests, removed minification since google seems to mangl…

…e it
  • Loading branch information...
commit 23d26d0880d41ed0bbe84aeae38f1479de264542 1 parent eb78f5a
@hunterloftis authored
View
0  build/cryo-0.0.1.min.js
No changes.
View
7 build/cryo-0.0.2.min.js
@@ -1,7 +0,0 @@
-/*
- The MIT license.
- @copyright Copyright (c) 2010 Skookum, skookum.com
-*/
-(function(){function f(a){return"object"===typeof a?a instanceof Array?"array":a instanceof Date?"date":"object":typeof a}function m(a,b,d){d=d||[];var c=f(a);if(-1!==t.indexOf(c)){c=d.indexOf(a);if(-1===c){var c={},e;for(e in a)a.hasOwnProperty(e)&&(c[e]=m(a[e],b,d));c=b.push({contents:c,value:n(a)})-1;d[c]=a}return g+c}return n(a)}function p(a,b){if(h(a,g)){var d=parseInt(a.slice(g.length),10),c=b[d],d=q(c.value),c=c.contents,e;for(e in c)d[e]=p(c[e],b);return d}return q(a)}function n(a){var b=
-f(a);return"undefined"===b?r:"function"===b?j+a.toString():"date"===b?k+a.getTime():Infinity===a?s:a}function q(a){if("string"===f(a)){if(a===r)return;if(h(a,j)){a=a.slice(j.length);var b=a.indexOf("(")+1,d=a.indexOf(")",b),b=a.slice(b,d),d=a.indexOf("{")+1,c=a.lastIndexOf("}")-1;a=a.slice(d,c);return new Function(b,a)}if(h(a,k))return a=parseInt(a.slice(k.length),10),new Date(a);if(a===s)return Infinity}return a}function h(a,b){return"string"===f(a)&&a.slice(0,b.length)===b}var t=["object","array",
-"date","function"],g="_CRYO_REF_",s="_CRYO_INFINITY_",j="_CRYO_FUNCTION_",r="_CRYO_UNDEFINED_",k="_CRYO_DATE_",l={stringify:function(a){var b=[];a=m(a,b);return JSON.stringify({root:a,references:b})},parse:function(a){a=JSON.parse(a);return p(a.root,a.references)}};"undefined"!==typeof define&&define.amd?define("Cryo",[],function(){return l}):"undefined"!==typeof module&&module.exports?module.exports=l:this.Cryo=l})();
View
18 build/cryo-0.0.3.js
@@ -71,16 +71,20 @@
return rebuildFromReferences(json.root, json.references);
}
- function rebuildFromReferences(item, references) {
+ function rebuildFromReferences(item, references, restoredItems) {
+ restoredItems = restoredItems || [];
if (starts(item, REFERENCE_FLAG)) {
var referenceIndex = parseInt(item.slice(REFERENCE_FLAG.length), 10);
- var ref = references[referenceIndex];
- var container = unwrap(ref.value);
- var contents = ref.contents;
- for (var key in contents) {
- container[key] = rebuildFromReferences(contents[key], references);
+ if (!restoredItems.hasOwnProperty(referenceIndex)) {
+ var ref = references[referenceIndex];
+ var container = unwrap(ref.value);
+ var contents = ref.contents;
+ for (var key in contents) {
+ container[key] = rebuildFromReferences(contents[key], references, restoredItems);
+ }
+ restoredItems[referenceIndex] = container;
}
- return container;
+ return restoredItems[referenceIndex];
}
return unwrap(item);
}
View
7 build/cryo-0.0.3.min.js
@@ -1,7 +0,0 @@
-/*
- The MIT license.
- @copyright Copyright (c) 2010 Skookum, skookum.com
-*/
-(function(){function f(a){return"object"===typeof a?a instanceof Array?"array":a instanceof Date?"date":"object":typeof a}function m(a,b,d){d=d||[];var c=f(a);if(-1!==t.indexOf(c)){c=d.indexOf(a);if(-1===c){var c={},e;for(e in a)a.hasOwnProperty(e)&&(c[e]=m(a[e],b,d));c=b.push({contents:c,value:n(a)})-1;d[c]=a}return g+c}return n(a)}function p(a,b){if(h(a,g)){var d=parseInt(a.slice(g.length),10),c=b[d],d=q(c.value),c=c.contents,e;for(e in c)d[e]=p(c[e],b);return d}return q(a)}function n(a){var b=
-f(a);return"undefined"===b?r:"function"===b?j+a.toString():"date"===b?k+a.getTime():Infinity===a?s:a}function q(a){if("string"===f(a)){if(a===r)return;if(h(a,j)){a=a.slice(j.length);var b=a.indexOf("(")+1,d=a.indexOf(")",b),b=a.slice(b,d),d=a.indexOf("{")+1,c=a.lastIndexOf("}")-1;a=a.slice(d,c);return new Function(b,a)}if(h(a,k))return a=parseInt(a.slice(k.length),10),new Date(a);if(a===s)return Infinity}return a}function h(a,b){return"string"===f(a)&&a.slice(0,b.length)===b}var t=["object","array",
-"date","function"],g="_CRYO_REF_",s="_CRYO_INFINITY_",j="_CRYO_FUNCTION_",r="_CRYO_UNDEFINED_",k="_CRYO_DATE_",l={stringify:function(a){var b=[];a=m(a,b);return JSON.stringify({root:a,references:b})},parse:function(a){a=JSON.parse(a);return p(a.root,a.references)}};"undefined"!==typeof define&&define.amd?define("Cryo",[],function(){return l}):"undefined"!==typeof module&&module.exports?module.exports=l:this.Cryo=l})();
View
2  makefile
@@ -17,7 +17,7 @@ build:
@echo "Building with closure compiler..."
@curl -s \
- -d compilation_level=SIMPLE_OPTIMIZATIONS \
+ -d compilation_level=WHITESPACE_ONLY \
-d output_format=text \
-d output_info=compiled_code \
--data-urlencode "js_code@${DEV}" \
View
24 test/browser.html
@@ -0,0 +1,24 @@
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Cryo-browser Test Suite</title>
+ <link rel="stylesheet" href="../vendor/mocha.css" />
+</head>
+<body>
+ <div id="mocha"></div>
+ <!-- mocha -->
+ <script src="../vendor/chai.js"></script>
+ <script>
+ assert = chai.assert;
+ expect = chai.expect;
+ </script>
+ <script src="../vendor/mocha.js"></script>
+ <script>mocha.setup('bdd')</script>
+ <!-- src -->
+ <script src="../build/cryo-0.0.3.js"></script>
+ <!-- tests -->
+ <script src="browser.test.js"></script>
+
+ <script>mocha.run();</script>
+</body>
+</html>
View
47 test/browser.test.js
@@ -0,0 +1,47 @@
+describe('Cryo - Browser', function() {
+
+ it('should be able to hydrate itself', function() {
+ var stringified = Cryo.stringify(Cryo);
+ var hydrated = Cryo.parse(stringified);
+
+ assert.isFunction(hydrated.parse);
+ assert.isFunction(hydrated.stringify);
+ });
+
+ it('should hydrate several objects referring to each other', function() {
+ var user1 = {
+ name: 'Hunter',
+ destroy: function() {
+ return 'destroyed ' + this.name;
+ }
+ };
+ var user2 = {
+ name: 'Jim'
+ };
+ var project = {
+ maintainers: [user1, user2],
+ title: 'Cryo'
+ };
+ var test = {
+ subject: project,
+ passing: true,
+ hooks: {
+ subscribed_users: [user1]
+ }
+ };
+ var stringified = Cryo.stringify(test);
+ var hydrated = Cryo.parse(stringified);
+
+ var result1 = test.hooks.subscribed_users[0].destroy();
+ var result2 = hydrated.hooks.subscribed_users[0].destroy();
+
+ hydrated.hooks.subscribed_users[0].name = 'Newname';
+ var result3 = hydrated.hooks.subscribed_users[0].destroy();
+
+ assert.strictEqual(result1, result2);
+ assert.strictEqual(result3, 'destroyed Newname');
+ assert.strictEqual(test.passing, hydrated.passing);
+ assert.strictEqual(test.subject.title, hydrated.subject.title);
+ });
+
+});
View
3,649 vendor/chai.js
3,649 additions, 0 deletions not shown
View
227 vendor/mocha.css
@@ -0,0 +1,227 @@
+@charset "UTF-8";
+body {
+ font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
+ padding: 60px 50px;
+}
+
+#mocha ul, #mocha li {
+ margin: 0;
+ padding: 0;
+}
+
+#mocha ul {
+ list-style: none;
+}
+
+#mocha h1, #mocha h2 {
+ margin: 0;
+}
+
+#mocha h1 {
+ margin-top: 15px;
+ font-size: 1em;
+ font-weight: 200;
+}
+
+#mocha h1 a {
+ text-decoration: none;
+ color: inherit;
+}
+
+#mocha h1 a:hover {
+ text-decoration: underline;
+}
+
+#mocha .suite .suite h1 {
+ margin-top: 0;
+ font-size: .8em;
+}
+
+.hidden {
+ display: none;
+}
+
+#mocha h2 {
+ font-size: 12px;
+ font-weight: normal;
+ cursor: pointer;
+}
+
+#mocha .suite {
+ margin-left: 15px;
+}
+
+#mocha .test {
+ margin-left: 15px;
+}
+
+#mocha .test.pending:hover h2::after {
+ content: '(pending)';
+ font-family: arial;
+}
+
+#mocha .test.pass.medium .duration {
+ background: #C09853;
+}
+
+#mocha .test.pass.slow .duration {
+ background: #B94A48;
+}
+
+#mocha .test.pass::before {
+ content: '';
+ font-size: 12px;
+ display: block;
+ float: left;
+ margin-right: 5px;
+ color: #00d6b2;
+}
+
+#mocha .test.pass .duration {
+ font-size: 9px;
+ margin-left: 5px;
+ padding: 2px 5px;
+ color: white;
+ -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
+ -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
+ box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ -ms-border-radius: 5px;
+ -o-border-radius: 5px;
+ border-radius: 5px;
+}
+
+#mocha .test.pass.fast .duration {
+ display: none;
+}
+
+#mocha .test.pending {
+ color: #0b97c4;
+}
+
+#mocha .test.pending::before {
+ content: '';
+ color: #0b97c4;
+}
+
+#mocha .test.fail {
+ color: #c00;
+}
+
+#mocha .test.fail pre {
+ color: black;
+}
+
+#mocha .test.fail::before {
+ content: '';
+ font-size: 12px;
+ display: block;
+ float: left;
+ margin-right: 5px;
+ color: #c00;
+}
+
+#mocha .test pre.error {
+ color: #c00;
+ max-height: 300px;
+ overflow: auto;
+}
+
+#mocha .test pre {
+ display: inline-block;
+ font: 12px/1.5 monaco, monospace;
+ margin: 5px;
+ padding: 15px;
+ border: 1px solid #eee;
+ border-bottom-color: #ddd;
+ -webkit-border-radius: 3px;
+ -webkit-box-shadow: 0 1px 3px #eee;
+ -moz-border-radius: 3px;
+ -moz-box-shadow: 0 1px 3px #eee;
+}
+
+#mocha .test h2 {
+ position: relative;
+}
+
+#mocha .test a.replay {
+ position: absolute;
+ top: 3px;
+ right: -20px;
+ text-decoration: none;
+ vertical-align: middle;
+ display: block;
+ width: 15px;
+ height: 15px;
+ line-height: 15px;
+ text-align: center;
+ background: #eee;
+ font-size: 15px;
+ -moz-border-radius: 15px;
+ border-radius: 15px;
+ -webkit-transition: opacity 200ms;
+ -moz-transition: opacity 200ms;
+ transition: opacity 200ms;
+ opacity: 0.2;
+ color: #888;
+}
+
+#mocha .test:hover a.replay {
+ opacity: 1;
+}
+
+#mocha-report.pass .test.fail {
+ display: none;
+}
+
+#mocha-report.fail .test.pass {
+ display: none;
+}
+
+#mocha-error {
+ color: #c00;
+ font-size: 1.5 em;
+ font-weight: 100;
+ letter-spacing: 1px;
+}
+
+#mocha-stats {
+ position: fixed;
+ top: 15px;
+ right: 10px;
+ font-size: 12px;
+ margin: 0;
+ color: #888;
+}
+
+#mocha-stats .progress {
+ float: right;
+ padding-top: 0;
+}
+
+#mocha-stats em {
+ color: black;
+}
+
+#mocha-stats a {
+ text-decoration: none;
+ color: inherit;
+}
+
+#mocha-stats a:hover {
+ border-bottom: 1px solid #eee;
+}
+
+#mocha-stats li {
+ display: inline-block;
+ margin: 0 5px;
+ list-style: none;
+ padding-top: 11px;
+}
+
+code .comment { color: #ddd }
+code .init { color: #2F6FAD }
+code .string { color: #5890AD }
+code .keyword { color: #8A6343 }
+code .number { color: #2F6FAD }
View
5,012 vendor/mocha.js
5,012 additions, 0 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.