1 if(!dojo._hasResource["tests._base.lang"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["tests._base.lang"] = true;
3 dojo.provide("tests._base.lang");
5 tests.register("tests._base.lang",
15 dojo.mixin(dest, src);
16 t.assertEqual("function", typeof dest["foo"]);
17 t.assertEqual("string", typeof dest["bar"]);
28 dojo.extend(dest, src);
29 var test = new dest();
30 t.assertEqual("function", typeof test["foo"]);
31 t.assertEqual("string", typeof test["bar"]);
35 t.assertFalse(dojo.isObject(true));
36 t.assertFalse(dojo.isObject(false));
37 t.assertFalse(dojo.isObject("foo"));
38 t.assertTrue(dojo.isObject(new String("foo")));
39 t.assertTrue(dojo.isObject(null));
40 t.assertTrue(dojo.isObject({}));
41 t.assertTrue(dojo.isObject([]));
42 t.assertTrue(dojo.isObject(new Array()));
46 t.assertTrue(dojo.isArray([]));
47 t.assertTrue(dojo.isArray(new Array()));
48 t.assertFalse(dojo.isArray({}));
51 function isArrayLike(t){
52 t.assertFalse(dojo.isArrayLike("thinger"));
53 t.assertTrue(dojo.isArrayLike(new Array()));
54 t.assertFalse(dojo.isArrayLike({}));
55 t.assertTrue(dojo.isArrayLike(arguments));
59 t.assertFalse(dojo.isString(true));
60 t.assertFalse(dojo.isString(false));
61 t.assertTrue(dojo.isString("foo"));
62 t.assertTrue(dojo.isString(new String("foo")));
63 t.assertFalse(dojo.isString(null));
64 t.assertFalse(dojo.isString({}));
65 t.assertFalse(dojo.isString([]));
69 var scope = { foo: "bar" };
70 var scope2 = { foo: "baz" };
71 function thinger(arg1, arg2){
72 return [this.foo, arg1, arg2];
75 var st1 = dojo.partial(thinger);
76 t.assertEqual("bar", st1.call(scope)[0]);
77 t.assertEqual(undefined, st1()[0]);
78 var st2 = dojo.partial(thinger, "foo", "bar");
79 t.assertEqual("bar", st2()[2]);
80 var st3 = dojo.partial(thinger, "foo", "bar");
83 function nestedPartial(t){
84 function thinger(arg1, arg2){
88 var st1 = dojo.partial(thinger, "foo");
89 t.assertEqual(undefined, st1()[1]);
90 t.assertEqual("bar", st1("bar")[1]);
92 // partials can accumulate
93 var st2 = dojo.partial(st1, "thud");
94 t.assertEqual("foo", st2()[0]);
95 t.assertEqual("thud", st2()[1]);
99 var scope = { foo: "bar" };
100 var scope2 = { foo: "baz" };
102 return [this.foo, arguments.length];
105 var st1 = dojo.hitch(scope, thinger);
106 t.assertEqual("bar", st1()[0]);
107 t.assertEqual(0, st1()[1]);
109 var st2 = dojo.hitch(scope2, thinger);
110 t.assertEqual("baz", st2()[0]);
111 t.assertEqual(0, st1()[1]);
112 t.assertEqual(1, st1("blah")[1]);
114 // st2 should be "scope proof"
115 t.assertEqual("baz", st2.call(scope)[0]);
118 function hitchWithArgs(t){
119 var scope = { foo: "bar" };
120 var scope2 = { foo: "baz" };
122 return [this.foo, arguments.length];
125 var st1 = dojo.hitch(scope, thinger, "foo", "bar");
126 t.assertEqual("bar", st1()[0]);
127 t.assertEqual(2, st1()[1]);
128 var st2 = dojo.hitch(scope2, thinger, "foo", "bar");
129 t.assertEqual("baz", st2()[0]);
130 t.assertEqual(2, st2()[1]);
133 function hitchAsPartial(t){
134 var scope = { foo: "bar" };
135 var scope2 = { foo: "baz" };
136 function thinger(arg1, arg2){
137 return [this.foo, arg1, arg2];
140 var st1 = dojo.hitch(null, thinger);
141 t.assertEqual("bar", st1.call(scope)[0]);
142 t.assertEqual(undefined, st1()[0]);
143 var st2 = dojo.hitch(null, thinger, "foo", "bar");
144 t.assertEqual("bar", st2()[2]);
145 var st3 = dojo.hitch(null, thinger, "foo", "bar");
148 function _toArray(t){
149 var obj1 = [ 'foo', 'bar', 'spam', 'ham' ];
152 return dojo._toArray(arguments);
154 var obj2 = thinger.apply(this, obj1);
155 t.assertEqual(obj1[0], obj2[0]);
159 var obj1 = {foo: 'bar', answer: 42, jan102007: new Date(2007, 0, 10),
163 1, "b", 2.3, true, false
164 //, function(){ return 4; }, /\d+/gm
168 var obj2 = dojo.clone(obj1);
169 t.assertEqual(obj1.foo, obj2.foo);
170 t.assertEqual(obj1.answer, obj2.answer);
171 t.assertEqual(obj1.jan102007, obj2.jan102007);
172 t.assertEqual(obj1.baz.a, obj2.baz.a);
173 for(var i = 0; i < obj1.baz.b.length; ++i){
174 t.assertEqual(obj1.baz.b[i], obj2.baz.b[i]);