core.html revision 9982ae2753aea312f8260f66903f5cfb1d202d22
1310N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
1310N/A<html>
1310N/A<head>
1310N/A<title>YUI Core Tests</title>
1310N/A</head>
1310N/A
1310N/A<body class="yui3-skin-sam">
1310N/A<h1>Core Tests</h1>
1310N/A<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
1310N/A
1310N/A<script type="text/javascript" src="/build/yui/yui.js"></script>
1310N/A<script type="text/javascript">
1310N/A
1310N/A YUI({
1310N/A filter: "debug",
1310N/A logExclude: {Dom: true, Selector: true, Node: true, attribute: true, base: true, event: true, widget: true}
1310N/A }).use("dump", "test", "console", function(Y) {
1310N/A
1310N/A var button = Y.one('#btnRun');
1310N/A
1310N/A // Set up the page
1310N/A button.set("disabled", false);
1310N/A
1310N/A Y.on("click", function() {
1310N/A Y.Test.Runner.run();
1310N/A }, button);
1310N/A
1310N/A var myConsole = new Y.Console().render();
1310N/A
1310N/A var testCore = new Y.Test.Case({
1310N/A
1310N/A name: "Core tests",
1310N/A
1310N/A 'cached functions should execute only once per input': function() {
1310N/A
1310N/A var r1 = "", r2 = "", r3 = "";
1310N/A
1310N/A var f1 = function(a) {
1310N/A r1 += a;
1310N/A };
1310N/A var c1 = Y.cached(f1);
1310N/A
1310N/A c1('a');
1310N/A c1('b');
1310N/A c1('a');
1310N/A c1('b');
1310N/A c1('a');
1310N/A c1('b');
1310N/A
1310N/A Y.Assert.areEqual('ab', r1);
1310N/A
1310N/A var f2 = function(a, b) {
1310N/A r2 += (a + b);
1310N/A };
1310N/A var c2 = Y.cached(f2);
1310N/A
1310N/A c2('a', 'b');
1310N/A c2('c', 'd');
1310N/A c2('a', 'b');
1310N/A c2('c', 'd');
1310N/A c2('a', 'b');
1310N/A c2('c', 'd');
1310N/A
1310N/A var o = new Y.EventTarget();
1310N/A o.foo = 1;
1310N/A
1310N/A var f3 = function(a) {
1310N/A Y.Assert.areEqual(1, this.foo);
1310N/A r3 += a;
1310N/A };
1310N/A
1310N/A var c3 = Y.cached(Y.bind(f3, o), {
1310N/A a: 'z'
1310N/A });
1310N/A
1310N/A c3('a');
1310N/A c3('b');
1310N/A c3('a');
1310N/A c3('b');
1310N/A c3('a');
1310N/A c3('b');
1310N/A
1310N/A Y.Assert.areEqual('b', r3);
1310N/A }
1310N/A });
1310N/A
1310N/A Y.Test.Runner.add(testCore);
1310N/A Y.Test.Runner.run();
1310N/A });
1310N/A</script>
1310N/A</body>
1310N/A</html>
1310N/A