object.html revision cb4f4f79feb7498d1f3406b88fb62209e5f5a444
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore<script type="text/javascript" src="/build/yui/yui.js"></script>
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore(function() {
35cf6dd5c2320d93c353e64d1b4aa8c50ebf7722Adam Moore logExclude: {
35cf6dd5c2320d93c353e64d1b4aa8c50ebf7722Adam Moore attribute: true,
35cf6dd5c2320d93c353e64d1b4aa8c50ebf7722Adam Moore event: true,
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore // deprecated: true,
35cf6dd5c2320d93c353e64d1b4aa8c50ebf7722Adam Moore widget: true,
35cf6dd5c2320d93c353e64d1b4aa8c50ebf7722Adam Moore selector: true
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore useConsole: true
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore }).use("dump", "test", "console", "event-custom", function(Y) {
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore var button = Y.get('#btnRun');
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore // Set up the page
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore button.set("disabled", false);
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.on("click", function() {
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore var myConsole = new Y.Console().render();
0dca577a07715960da42d47787eecc25b285182fAdam Moore var testCase = new Y.Test.Case({
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore name: "Object tests",
0dca577a07715960da42d47787eecc25b285182fAdam Moore test_deep_getValue: function() {
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Assert.areEqual('c', Y.Object.getValue(o, 'c1'));
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Assert.areEqual('a', Y.Object.getValue(o, ['a1', 'a2', 'a3']));
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Assert.areEqual(undefined, Y.Object.getValue(o, ['b1', 'b2', 'b3']));
0dca577a07715960da42d47787eecc25b285182fAdam Moore Y.Assert.areEqual(undefined, Y.Object.getValue(null, ['b1', 'b2', 'b3']));
0dca577a07715960da42d47787eecc25b285182fAdam Moore test_deep_setValue: function() {
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Object.setValue(o, 'c1', 'changed_c');
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Object.setValue(o, ['a1', 'a2', 'a3'], 'changed_a');
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Object.setValue(o, ['b1', 'b2', 'b3'], 'changed_b');
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Assert.areEqual('changed_c', Y.Object.getValue(o, 'c1'));
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Assert.areEqual('changed_a', Y.Object.getValue(o, ['a1', 'a2', 'a3']));
3395e5fc071521d4e6b258ef4c7c0ef38601b94eAdam Moore Y.Assert.areEqual(undefined, Y.Object.getValue(o, ['b1', 'b2', 'b3']));
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore test_people_messing_up_object_prototype: function() {
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore var count = 0;
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore Y.Assert.isFalse(Y.Object.hasKey({}, 'foo'), 'hasKey should not find proto props');
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore Y.Assert.areEqual(0, Y.Object.size({}), 'size should not count proto additions');
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore Y.Assert.areEqual(0, Y.Object.keys({}), 'keys should not include proto additions');
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore Y.Assert.areEqual(0, Y.Object.values({}), 'values should not count proto additions');
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore Y.Assert.isFalse(Y.Object.hasValue({}, 'hello!'), 'hasValue should not look at proto additions');
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore Y.Object.each({}, function () {
4390434761f176b0f8d7a71c00a6e0141aa1752cAdam Moore Y.Assert.areEqual(0, count, 'each should not iterate proto props unless asked to do so.');