lang.html revision f42590c0af8667f2f7ed36bd6d47620ec9ffa4d7
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<iframe name="xframe" id="xframe" src="assets/xframe.html"></iframe>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<script type="text/javascript" src="/build/yui/yui.js"></script>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe(function() {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe filter: "debug",
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe useConsole: true,
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe logExclude: {Dom: true, Selector: true, Node: true, attribute: true, base: true, event: true, widget: true}
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe }).use("dump", "test", "console", "event-custom", function(Y) {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe var button = Y.get('#btnRun'),
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe // Set up the page
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe button.set("disabled", false);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Y.on("click", function() {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe // var myConsole = new Y.Console().render();
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe var testObject = new Y.Test.Case({
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe name: "Lang tests",
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe test_is_array: function() {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isTrue(Y.Lang.isArray([1, 2]), "Array literals are arrays");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray({"one": "two"}), "Object literals are not arrays");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe var a = new Array();
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe a["one"] = "two";
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isTrue(Y.Lang.isArray(a), "Associative array are arrays");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(document.getElementsByTagName("body")),
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe "Element collections are array-like, but not arrays");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(null), "null is not an array");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(''), "'' is not an array");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(undefined), "undefined is not an array");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isTrue(Y.Lang.isArray(xframe.arr), "Cross frame array failure");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(xframe.far), "Cross frame fake array failure");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(xframe.obj), "Cross frame object failure");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(xframe.fun), "Cross frame function failure");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(xframe.boo), "Cross frame boolean failure");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(xframe.str), "Cross frame string failure");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(xframe.nul), "Cross frame null failure");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(xframe.und), "Cross frame undefined failure");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe // alert(xframe.arr.constructor.prototype == Array.prototype);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe // alert(xframe.arr.constructor.prototype == xframe.Array.prototype);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe test_is_boolean: function() {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isTrue(Y.Lang.isBoolean(false), "false failed boolean check");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isBoolean(1), "the number 1 is not a boolean");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isBoolean("true"), "the string 'true' is not a boolean");
Assert.isFalse(Y.Lang.isNumber('123.123'), "the string '123.123' is not a number, even though it can be cast into one");
Assert.isFalse(Y.Lang.isNumber(1/0), "undefined numbers and infinity are not numbers we want to use");
Assert.isFalse(Y.Lang.isObject(null), "null should return false even though it technically is an object");
Assert.isFalse(Y.Lang.isDate(badDateObj), "A date object containing and invalid date should be false.");
Y.Test.Runner.add(testObject);