Skip to content

Commit

Permalink
add tests sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
holyshared committed Dec 3, 2011
1 parent e6db4a5 commit 6d0d862
Show file tree
Hide file tree
Showing 11 changed files with 4,260 additions and 0 deletions.
182 changes: 182 additions & 0 deletions Source/CacheManager.js
@@ -0,0 +1,182 @@
/*
---
name: CacheManager
description:
license: MIT-style
authors:
- Noritaka Horio
requires:
- Core/Core
- Core/String
- Core/Object
- Core/Type
- Core/JSON
provides:
- CacheManager
- CacheManager.CacheContent
- CacheManager.LocalStorage
- CacheManager.SessionStorage
- CacheManager.HashStorage
...
*/

(function(global){

/**
* CacheManager
*/
var CacheManager = global.CacheManager = function (storage){

this.storage = storage;

}.implement({


/*
Example:
var content = {
name: 'foo',
age: 28,
email: 'foo@example.com'
};
cacheManager.set('name=foo&age=28', content);
cacheManager.set('name=foo&age=28', content, 1 * 60 * 60 * 1000);
*/
set: function(key, content, limit){
var cacheTime = new Date(),
cacheContent = null;

if (Type.isNumber(limit) === false) {
throw new TypeError('cache limit invalid.');
}

cacheTime.setTime(cacheTime.getTime() + limit);

cacheContent = JSON.encode({
limit: cacheTime.getTime(),
content: content
});
this.storage.setItem(key, cacheContent);
},

/*
Example:
var cache = cacheManager.get('name=foo&age=28');
if (cache.isLimit() === true) {
//remove a cache content
cache.destory();
}
*/
get: function(key){
var cache = null,
cacheContent = this.storage.getItem(key);

if (!cacheContent) {
return null;
}

cache = JSON.decode(cacheContent);
cache = Object.merge(cache, {
key: key,
storage: this
});

return new CacheManager.CacheContent(cache);
}

});

//localStorage alias name
CacheManager.LocalStorage = global.localStorage;

//sessionStorage alias name
CacheManager.SessionStorage = global.sessionStorage;

CacheManager.HashStorage = {
_store: {},
setItem: function(key, content){
if (!Type.isString(key)){
throw new TypeError('invalid key');
}
if (!content){
throw new TypeError('content is not empty');
}
this._store[key] = content;
},
getItem: function(key){
if (!this._store[key]){
return null;
}
return this._store[key];
},
removeItem: function(key){
delete this._store[key];
}
};


/*
Example:
var content = CacheContent({
storage: storage,
key: 'name=foo&age=28',
limit: 1 * 60 * 60 * 1000 + new Date().getTime(),
content: {
foo: 'foo',
bar: 'bar'
}
});
content.getKey();
content.getStorage();
content.getLimit()
content.getContent();
content.isLimit();
content.destory();
*/

CacheManager.CacheContent = function (properties){

var instance = this, getter = null;

//generate getter methods
Object.each(properties, function(value, key){
getter = 'get' + key.capitalize();
instance[getter] = function(){
return properties[key];
};
});

Object.merge(instance, {

isLimit: function(){
if (instance.limit > new Date().getTime()){
return false;
} else {
return true;
}
},

destroy: function(){
instance.storage.removeItem(instance.key);
}

});

};

}(this));
166 changes: 166 additions & 0 deletions Tests/jasmine/css/jasmine.css
@@ -0,0 +1,166 @@
body {
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
}


.jasmine_reporter a:visited, .jasmine_reporter a {
color: #303;
}

.jasmine_reporter a:hover, .jasmine_reporter a:active {
color: blue;
}

.run_spec {
float:right;
padding-right: 5px;
font-size: .8em;
text-decoration: none;
}

.jasmine_reporter {
margin: 0 5px;
}

.banner {
color: #303;
background-color: #fef;
padding: 5px;
}

.logo {
float: left;
font-size: 1.1em;
padding-left: 5px;
}

.logo .version {
font-size: .6em;
padding-left: 1em;
}

.runner.running {
background-color: yellow;
}


.options {
text-align: right;
font-size: .8em;
}




.suite {
border: 1px outset gray;
margin: 5px 0;
padding-left: 1em;
}

.suite .suite {
margin: 5px;
}

.suite.passed {
background-color: #dfd;
}

.suite.failed {
background-color: #fdd;
}

.spec {
margin: 5px;
padding-left: 1em;
clear: both;
}

.spec.failed, .spec.passed, .spec.skipped {
padding-bottom: 5px;
border: 1px solid gray;
}

.spec.failed {
background-color: #fbb;
border-color: red;
}

.spec.passed {
background-color: #bfb;
border-color: green;
}

.spec.skipped {
background-color: #bbb;
}

.messages {
border-left: 1px dashed gray;
padding-left: 1em;
padding-right: 1em;
}

.passed {
background-color: #cfc;
display: none;
}

.failed {
background-color: #fbb;
}

.skipped {
color: #777;
background-color: #eee;
display: none;
}


/*.resultMessage {*/
/*white-space: pre;*/
/*}*/

.resultMessage span.result {
display: block;
line-height: 2em;
color: black;
}

.resultMessage .mismatch {
color: black;
}

.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
max-height: 5em;
overflow: auto;
border: 1px inset red;
padding: 1em;
background: #eef;
}

.finished-at {
padding-left: 1em;
font-size: .6em;
}

.show-passed .passed,
.show-skipped .skipped {
display: block;
}


#jasmine_content {
position:fixed;
right: 100%;
}

.runner {
border: 1px solid gray;
display: block;
margin: 5px 0;
padding: 2px 0 2px 10px;
}
24 changes: 24 additions & 0 deletions Tests/jasmine/index.html
@@ -0,0 +1,24 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="css/jasmine.css">
<script type="text/javascript" src="js/jasmine.js"></script>
<script type="text/javascript" src="js/jasmine-html.js"></script>
<script type="text/javascript" src="js/mootools-core-1.4.1.js"></script>

<script type="text/javascript" src="../../Source/CacheManager.js"></script>
<script type="text/javascript" src="spec/cache-hash-storage-spec.js"></script>
<script type="text/javascript" src="spec/cache-session-storage-spec.js"></script>
<script type="text/javascript" src="spec/cache-local-storage-spec.js"></script>
</head>
<body>

<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>

</body>
</html>

0 comments on commit 6d0d862

Please sign in to comment.