lang.html revision cb4f4f79feb7498d1f3406b88fb62209e5f5a444
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<html>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<head>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<title>YUI Lang Tests</title>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync</head>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync<body class="yui3-skin-sam">
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<iframe name="xframe" id="xframe" src="assets/xframe.html"></iframe>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<h1>Lang Tests</h1>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<script type="text/javascript" src="/build/yui/yui.js"></script>
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync<script type="text/javascript">
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync(function() {
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync YUI({
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync base: "/build/",
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync filter: "debug",
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync useConsole: true,
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync logExclude: {Dom: true, Selector: true, Node: true, attribute: true, base: true, event: true, widget: true}
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync }).use("dump", "test", "console", "event-custom", function(Y) {
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Y.log(typeof NaN);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync var button = Y.get('#btnRun'),
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Assert = Y.Assert;
1e2bc03fd1fc133bd3a066b1557471e157df78f6vboxsync
5bcfdf9ef0306239498361e5021d008ad77bf539vboxsync // Set up the page
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync button.set("disabled", false);
c312e1b81dffe42e0fb766020fb8defaeade05d6vboxsync Y.on("click", function() {
c312e1b81dffe42e0fb766020fb8defaeade05d6vboxsync Y.Test.Runner.run();
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync }, button);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync // var myConsole = new Y.Console().render();
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync var testObject = new Y.Test.Case({
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync name: "Lang tests",
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync test_is_array: function() {
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync Assert.isTrue(Y.Lang.isArray([1, 2]), "Array literals are arrays");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray({"one": "two"}), "Object literals are not arrays");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync var a = new Array();
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync a["one"] = "two";
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isTrue(Y.Lang.isArray(a), "Associative array are arrays");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(document.getElementsByTagName("body")),
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync "Element collections are array-like, but not arrays");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(null), "null is not an array");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(''), "'' is not an array");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(undefined), "undefined is not an array");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isTrue(Y.Lang.isArray(xframe.arr), "Cross frame array failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(xframe.far), "Cross frame fake array failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(xframe.obj), "Cross frame object failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(xframe.fun), "Cross frame function failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(xframe.boo), "Cross frame boolean failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(xframe.str), "Cross frame string failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(xframe.nul), "Cross frame null failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isArray(xframe.und), "Cross frame undefined failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync // alert(xframe.arr.constructor.prototype == Array.prototype);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync // alert(xframe.arr.constructor.prototype == xframe.Array.prototype);
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync },
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync test_is_boolean: function() {
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isTrue(Y.Lang.isBoolean(false), "false failed boolean check");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isBoolean(1), "the number 1 is not a boolean");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isBoolean("true"), "the string 'true' is not a boolean");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync },
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync test_is_function: function() {
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync Assert.isTrue(Y.Lang.isFunction(function(){}), "a function is a function");
54828795a553ed0731f308ebda81675ad2c39d58vboxsync Assert.isFalse(Y.Lang.isFunction({foo: "bar"}), "an object is not a function");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
54828795a553ed0731f308ebda81675ad2c39d58vboxsync Assert.isTrue(Y.Lang.isFunction(xframe.fun), "Cross frame function failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isFunction(xframe.arr), "Cross frame array failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isFunction(xframe.obj), "Cross frame object failure");
54828795a553ed0731f308ebda81675ad2c39d58vboxsync Assert.isFalse(Y.Lang.isFunction(xframe.boo), "Cross frame boolean failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isFunction(xframe.str), "Cross frame string failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isFunction(xframe.nul), "Cross frame null failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isFunction(xframe.und), "Cross frame undefined failure");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync },
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync test_is_null: function() {
50f0e2e83362e100d306a411980d555d46aa00a8vboxsync Assert.isTrue(Y.Lang.isNull(null), "null is null");
54828795a553ed0731f308ebda81675ad2c39d58vboxsync Assert.isFalse(Y.Lang.isNull(undefined), "undefined is not null");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isNull(""), "empty string is not null");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync },
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync test_is_number: function() {
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isTrue(Y.Lang.isNumber(0), "0 is a number");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isTrue(Y.Lang.isNumber(123.123), "123.123 is a number");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isNumber('123.123'), "the string '123.123' is not a number, even though it can be cast into one");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync Assert.isFalse(Y.Lang.isNumber(1/0), "undefined numbers and infinity are not numbers we want to use");
b0dfb334954c0552bb583967a3077ec88fd00471vboxsync },
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync test_is_object: function() {
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isTrue(Y.Lang.isObject({}), "an object is an object");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isTrue(Y.Lang.isObject(function(){}), "a function is an object");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isTrue(Y.Lang.isObject([]), "an array is an object");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isFalse(Y.Lang.isObject(1), "numbers are not objects");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isFalse(Y.Lang.isObject(true), "boolean values are not objects");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isFalse(Y.Lang.isObject("{}"), "strings are not objects");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isFalse(Y.Lang.isObject(null), "null should return false even though it technically is an object");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isTrue(Y.Lang.isObject(xframe.obj), "Cross frame object failure");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isTrue(Y.Lang.isObject(xframe.fun), "Cross frame function failure");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isTrue(Y.Lang.isObject(xframe.arr), "Cross frame array failure");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isFalse(Y.Lang.isObject(xframe.boo), "Cross frame boolean failure");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isFalse(Y.Lang.isObject(xframe.str), "Cross frame string failure");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isFalse(Y.Lang.isObject(xframe.nul), "Cross frame null failure");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync Assert.isFalse(Y.Lang.isObject(xframe.und), "Cross frame undefined failure");
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync
80523be8dba75b5eb32569fd72ddf54f3b009025vboxsync },
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync test_is_string: function() {
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isTrue(Y.Lang.isString("{}"), "a string is a string");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isFalse(Y.Lang.isString({foo: "bar"}), "an object is not a string");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isFalse(Y.Lang.isString(123), "a number is not a string");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isFalse(Y.Lang.isString(true), "boolean values are not strings");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync },
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync test_is_undefined: function() {
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isTrue(Y.Lang.isUndefined(undefined), "undefined is undefined");
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync Assert.isFalse(Y.Lang.isUndefined(false), "boolean false is not undefined");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isFalse(Y.Lang.isUndefined(null), "null is not undefined");
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync },
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync test_trim: function() {
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync Assert.areEqual(Y.Lang.trim(" My String"), "My String");
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync Assert.areEqual(Y.Lang.trim("My String "), "My String");
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync Assert.areEqual(Y.Lang.trim(" My String "), "My String");
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync Assert.areEqual(Y.Lang.trim(null), null);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync Assert.areEqual(Y.Lang.trim(undefined), undefined);
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync Assert.areEqual(Y.Lang.trim({}), "[object Object]");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync },
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
b60e4b0625949fd68ed97f1353e2174c5b3192e5vboxsync test_is_value: function() {
b60e4b0625949fd68ed97f1353e2174c5b3192e5vboxsync Assert.isFalse(Y.Lang.isValue(null), "null should be false");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isFalse(Y.Lang.isValue(undefined), "undefined should be false");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isFalse(Y.Lang.isValue(parseInt("adsf", 10)), "NaN should be false");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isFalse(Y.Lang.isValue(1/0), "undefined numbers and infinity should be false");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isTrue(Y.Lang.isValue(new Date()), "date should be true");
5d05aa26ae1949e6f0bbc149d8b8e39495710ac7vboxsync Assert.isTrue(Y.Lang.isValue(""), "Empty string should be true");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync Assert.isTrue(Y.Lang.isValue(false), "false should be true");
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync },
8d29e9dc0d280b7b26834132b9ce14a3a845a7fdvboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync test_is_date: function() {
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Assert.isFalse(Y.Lang.isDate(null), "null should be false");
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Assert.isFalse(Y.Lang.isDate(undefined), "undefined should be false");
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Assert.isFalse(Y.Lang.isDate(parseInt("adsf", 10)), "NaN should be false");
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Assert.isFalse(Y.Lang.isDate(1/0), "undefined numbers and infinity should be false");
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Assert.isFalse(Y.Lang.isDate(NaN), "NaN should be false");
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync Assert.isTrue(Y.Lang.isDate(new Date()), "date should be true");
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync Assert.isFalse(Y.Lang.isDate(""), "Empty string should be false");
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync Assert.isFalse(Y.Lang.isDate(false), "false should be false");
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync Assert.isFalse(Y.Lang.isDate(xframe.fun), "Cross frame function should be false");
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync Assert.isTrue(Y.Lang.isDate(xframe.dat), "Cross frame date should be true");
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync var badDateObj = new Date('junk');
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Assert.isFalse(Y.Lang.isDate(badDateObj), "A date object containing and invalid date should be false.");
052deaa01d8fcd5cec4dff857833538940b751c3vboxsync }
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
755f4438e1e3a66f23230126b7df46d51006ac24vboxsync });
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Y.Test.Runner.add(testObject);
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync Y.Test.Runner.run();
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync });
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync})();
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync</script>
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync</body>
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync</html>
64e0c74b525c440a571ce06f3eb6234d75913d76vboxsync