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<html>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<head>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<title>YUI Lang Tests</title>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe</head>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<body class="yui-skin-sam">
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<iframe name="xframe" id="xframe" src="assets/xframe.html"></iframe>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<h1>Lang Tests</h1>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<script type="text/javascript" src="/build/yui/yui.js"></script>
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe<script type="text/javascript">
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe(function() {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe YUI({
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe base: "/build/",
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
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Y.log(typeof NaN);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe var button = Y.get('#btnRun'),
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert = Y.Assert;
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe // Set up the page
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe button.set("disabled", false);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Y.on("click", function() {
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Y.Test.Runner.run();
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe }, button);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe // var myConsole = new Y.Console().render();
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe var testObject = new Y.Test.Case({
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe name: "Lang tests",
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
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
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
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe Assert.isFalse(Y.Lang.isArray(document.getElementsByTagName("body")),
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe "Element collections are array-like, but not arrays");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
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
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
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe // alert(xframe.arr.constructor.prototype == Array.prototype);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe // alert(xframe.arr.constructor.prototype == xframe.Array.prototype);
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe },
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
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");
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe },
d2a70789f056fc6c9ce3ab047b52126d80b0e3daRichard Lowe
test_is_function: function() {
Assert.isTrue(Y.Lang.isFunction(function(){}), "a function is a function");
Assert.isFalse(Y.Lang.isFunction({foo: "bar"}), "an object is not a function");
Assert.isTrue(Y.Lang.isFunction(xframe.fun), "Cross frame function failure");
Assert.isFalse(Y.Lang.isFunction(xframe.arr), "Cross frame array failure");
Assert.isFalse(Y.Lang.isFunction(xframe.obj), "Cross frame object failure");
Assert.isFalse(Y.Lang.isFunction(xframe.boo), "Cross frame boolean failure");
Assert.isFalse(Y.Lang.isFunction(xframe.str), "Cross frame string failure");
Assert.isFalse(Y.Lang.isFunction(xframe.nul), "Cross frame null failure");
Assert.isFalse(Y.Lang.isFunction(xframe.und), "Cross frame undefined failure");
},
test_is_null: function() {
Assert.isTrue(Y.Lang.isNull(null), "null is null");
Assert.isFalse(Y.Lang.isNull(undefined), "undefined is not null");
Assert.isFalse(Y.Lang.isNull(""), "empty string is not null");
},
test_is_number: function() {
Assert.isTrue(Y.Lang.isNumber(0), "0 is a number");
Assert.isTrue(Y.Lang.isNumber(123.123), "123.123 is a number");
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");
},
test_is_object: function() {
Assert.isTrue(Y.Lang.isObject({}), "an object is an object");
Assert.isTrue(Y.Lang.isObject(function(){}), "a function is an object");
Assert.isTrue(Y.Lang.isObject([]), "an array is an object");
Assert.isFalse(Y.Lang.isObject(1), "numbers are not objects");
Assert.isFalse(Y.Lang.isObject(true), "boolean values are not objects");
Assert.isFalse(Y.Lang.isObject("{}"), "strings are not objects");
Assert.isFalse(Y.Lang.isObject(null), "null should return false even though it technically is an object");
Assert.isTrue(Y.Lang.isObject(xframe.obj), "Cross frame object failure");
Assert.isTrue(Y.Lang.isObject(xframe.fun), "Cross frame function failure");
Assert.isTrue(Y.Lang.isObject(xframe.arr), "Cross frame array failure");
Assert.isFalse(Y.Lang.isObject(xframe.boo), "Cross frame boolean failure");
Assert.isFalse(Y.Lang.isObject(xframe.str), "Cross frame string failure");
Assert.isFalse(Y.Lang.isObject(xframe.nul), "Cross frame null failure");
Assert.isFalse(Y.Lang.isObject(xframe.und), "Cross frame undefined failure");
},
test_is_string: function() {
Assert.isTrue(Y.Lang.isString("{}"), "a string is a string");
Assert.isFalse(Y.Lang.isString({foo: "bar"}), "an object is not a string");
Assert.isFalse(Y.Lang.isString(123), "a number is not a string");
Assert.isFalse(Y.Lang.isString(true), "boolean values are not strings");
},
test_is_undefined: function() {
Assert.isTrue(Y.Lang.isUndefined(undefined), "undefined is undefined");
Assert.isFalse(Y.Lang.isUndefined(false), "boolean false is not undefined");
Assert.isFalse(Y.Lang.isUndefined(null), "null is not undefined");
},
test_trim: function() {
Assert.areEqual(Y.Lang.trim(" My String"), "My String");
Assert.areEqual(Y.Lang.trim("My String "), "My String");
Assert.areEqual(Y.Lang.trim(" My String "), "My String");
Assert.areEqual(Y.Lang.trim(null), null);
Assert.areEqual(Y.Lang.trim(undefined), undefined);
Assert.areEqual(Y.Lang.trim({}), "[object Object]");
},
test_is_value: function() {
Assert.isFalse(Y.Lang.isValue(null), "null should be false");
Assert.isFalse(Y.Lang.isValue(undefined), "undefined should be false");
Assert.isFalse(Y.Lang.isValue(parseInt("adsf", 10)), "NaN should be false");
Assert.isFalse(Y.Lang.isValue(1/0), "undefined numbers and infinity should be false");
Assert.isTrue(Y.Lang.isValue(new Date()), "date should be true");
Assert.isTrue(Y.Lang.isValue(""), "Empty string should be true");
Assert.isTrue(Y.Lang.isValue(false), "false should be true");
},
test_is_date: function() {
Assert.isFalse(Y.Lang.isDate(null), "null should be false");
Assert.isFalse(Y.Lang.isDate(undefined), "undefined should be false");
Assert.isFalse(Y.Lang.isDate(parseInt("adsf", 10)), "NaN should be false");
Assert.isFalse(Y.Lang.isDate(1/0), "undefined numbers and infinity should be false");
Assert.isFalse(Y.Lang.isDate(NaN), "NaN should be false");
Assert.isTrue(Y.Lang.isDate(new Date()), "date should be true");
Assert.isFalse(Y.Lang.isDate(""), "Empty string should be false");
Assert.isFalse(Y.Lang.isDate(false), "false should be false");
Assert.isFalse(Y.Lang.isDate(xframe.fun), "Cross frame function should be false");
Assert.isTrue(Y.Lang.isDate(xframe.dat), "Cross frame date should be true");
var badDateObj = new Date('junk');
Assert.isFalse(Y.Lang.isDate(badDateObj), "A date object containing and invalid date should be false.");
}
});
Y.Test.Runner.add(testObject);
Y.Test.Runner.run();
});
})();
</script>
</body>
</html>