index.html revision 97313c46f83d59ff6ac32b852c5d055a0ca57e2d
a48fa4b49c58246b297e0fd38e5fb85b985379f1Bob Halley<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<script type="text/javascript" src="/build/yui/yui.js"></script>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<script type="text/javascript" src="/build/cache/cache-debug.js" id="buildsrc"></script>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson //filter: "debug",
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson useConsole: true,
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson insertBefore: "buildsrc"
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson }).use("console", "test", "dump", "cache", function(Y) {
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson // Set up the page
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson BTNRUN = Y.get("#btnRun");
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson BTNRUN.set("disabled", false);
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson Y.on("click", function(e){
b90dd6c0a9df584619d3c47be7c9417f55d5ccf6Bob Halley var myConsole = new Y.Console().render();
b90dd6c0a9df584619d3c47be7c9417f55d5ccf6Bob Halley var testClass = new Y.Test.Case({
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson name: "Class Tests",
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson testDefaults: function() {
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson // TODO: remove empty config
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson var cache = new Y.Cache({});
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson ASSERT.isInstanceOf(Y.Cache, cache, "Expected instance of Y.Cache.");
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson ASSERT.areSame(0, cache.get("max"), "Expected default max of 0.");
70680fa51b0147c726b939b72b2420249429756aBob Halley ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array.");
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley testDestructor: function() {
16803617e47c83272013e45ba8eb83a3b11983edAndreas Gustafsson // TODO: remove empty config
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson var cache = new Y.Cache({});
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.isNull(cache.get("entries"), "Expected null array.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson var testBasic = new Y.Test.Case({
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson name: "Basic Tests",
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson testmax0: function() {
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson // TODO: remove empty config
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson var cache = new Y.Cache({});
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(0, cache.get("max"), "Expected max to be 0.");
672a41b5fef7722803645c1f0ca132972f0f940aAndreas Gustafsson ASSERT.areSame(0, cache.get("size"), "Expected 0 entries.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.isNull(cache.retrieve(1), "Expected null cached response.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson testmax2: function() {
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson var cache = new Y.Cache({max:2});
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(2, cache.get("max"), "Expected max to be 2.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(1, cache.get("size"), "Expected 1 entry.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(2, cache.get("size"), "Expected 2 entries.");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(2, cache.get("size"), "Expected 2 entries (still).");
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson testmax2to1: function() {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson var cache = new Y.Cache({max:2});
4d5f44e7933f4cb691e8f4cf3b4b5f61c27e2b1cAndreas Gustafsson ASSERT.areSame(1, cache.get("size"), "Expected 1 entry.");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ASSERT.areSame(1, cache.get("size"), "Expected 1 entry (still).");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testmax2to0: function() {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson var cache = new Y.Cache({max:2});
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array.");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array (still).");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testmax2toNegative: function() {
2fdaa940ccd0c671a3675d4674c0bd9b8a3f3fb4Andreas Gustafsson var cache = new Y.Cache({max:2});
8cc03bfc0c9eaee8c186843fef75c58093616d04Mark Andrews ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array.");
8cc03bfc0c9eaee8c186843fef75c58093616d04Mark Andrews ARRAYASSERT.isEmpty(cache.get("entries"), "Expected empty array (still).");
7c956aeeeb8da3fd3912b1fb8024ff274e3b07ebAndreas Gustafsson ASSERT.areSame(-5, cache.get("max"), "Expected negative value normalized to 0.");
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testRetrieve: function() {
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley var cache = new Y.Cache({max:2}),
e5256e34b4a26a26088b2dc5ca621b42c0750256Andreas Gustafsson cachedresponse;
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley cachedresponse = cache.retrieve(1).response;
40d01ce8f3a1889f5799d9b22b26d5398fa75a1bBob Halley ASSERT.areSame("a", cachedresponse, "Expected first cached response.");
8db66dc4eb654a2e295eaeab3aaf96e24c9ae7b7Bob Halley cachedresponse = cache.retrieve(2).response;
76860484adfbadeecfeb3a7132ede916ee2102ffBrian Wellington ASSERT.areSame("b", cachedresponse, "Expected second cached response.");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testFlush: function() {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley var cache = new Y.Cache({max:2});
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley ASSERT.areSame(0, cache.get("size"), "Expected empty cache.");
997e3113b7c91ec94e6274d31735f122e6e8209cAndreas Gustafsson var testEvents = new Y.Test.Case({
d80ccd47ad4b526f82590b6c182b4dd80006712eAndreas Gustafsson name: "Event Tests",
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testAdd: function() {
a0cad57966364095e4367f568389a8bd84afb2afAndreas Gustafsson var cache = new Y.Cache({max:2});
a0cad57966364095e4367f568389a8bd84afb2afAndreas Gustafsson cache.on("add", function(e) {
a0cad57966364095e4367f568389a8bd84afb2afAndreas Gustafsson }, this, true);
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testFlush: function() {
8eb5937a7e4cb8b5d7fcc1be17d34fdd014bbbb1Andreas Gustafsson var cache = new Y.Cache({max:2});
8eb5937a7e4cb8b5d7fcc1be17d34fdd014bbbb1Andreas Gustafsson cache.on("flush", function(e) {
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson // This function intentionally left blank
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson }, this, true);
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson testRequest: function() {
b70fc17acec2c036bb35a937ba00fbcf10848859David Lawrence var cache = new Y.Cache({max:2});
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.on("request", function(e) {
b70fc17acec2c036bb35a937ba00fbcf10848859David Lawrence }, this, true);
69930116e30137705d3b87d05cbfbc5712386fdeAndreas Gustafsson testRetrieveSuccess: function() {
69930116e30137705d3b87d05cbfbc5712386fdeAndreas Gustafsson var cache = new Y.Cache({max:2});
3b8932de20e12b07f9d874d5538d30e1fac9a9f4Andreas Gustafsson cache.on("retrieve", function(e) {
e21262ae8af5d12f64a2242e26338f36901ba4ccAndreas Gustafsson }, this, true);
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testRetrieveFailure: function() {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley var cache = new Y.Cache({max:2});
5f5bb44065a3e7f506e4afd4d81c89da2931bf1bBob Halley cache.on("retrieve", function(e) {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley }, this, true);
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson // This function intentionally left blank
3637ad3b4e59fc92d3c68b5eabc479bb0ebd570eAndreas Gustafsson testCancelAdd: function() {
3637ad3b4e59fc92d3c68b5eabc479bb0ebd570eAndreas Gustafsson var cache = new Y.Cache({max:2});
3637ad3b4e59fc92d3c68b5eabc479bb0ebd570eAndreas Gustafsson cache.on("add", function(e) {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley }, this, true);
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson // Test the cancel
4efe2e812cf8462ed781bfd79b644eaf17d6d2b7Andreas Gustafsson ASSERT.areSame(0, cache.get("size"), "Expected 0 entries.");
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson testCancelFlush: function() {
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson var cache = new Y.Cache({max:2});
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson cache.on("flush", function(e) {
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson }, this, true);
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson // Test the cancel
672a41b5fef7722803645c1f0ca132972f0f940aAndreas Gustafsson ASSERT.areSame(1, cache.get("size"), "Expected 1 entry.");
413d5565ba2af24f12dc54d6e6807af7f1a39867Andreas Gustafsson var testEntryManagement = new Y.Test.Case({
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley name: "Entry Management Tests",
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testAllowDuplicateEntries: function() {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley var cache = new Y.Cache({max:3});
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley ASSERT.areSame(3, cache.get("size"), "Expected 3 entries.");
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley testFreshness: function() {
36983956d7c3d9e294903eeda29548f67ac17daeBob Halley var cache = new Y.Cache({max:3});
cache.retrieve(1);
Y.Test.Runner.add(testClass);
Y.Test.Runner.add(testBasic);
Y.Test.Runner.add(testEvents);
Y.Test.Runner.add(testEntryManagement);