1 | define(["dojo", "doh", "../../../_base/sniff", "require"], function(dojo, doh, has, require){ |
---|
2 | doh.register("tests._base._loader.bootstrap", [ |
---|
3 | function hasConsole(t){ |
---|
4 | t.assertTrue("console" in dojo.global); |
---|
5 | t.assertTrue("assert" in console); |
---|
6 | t.assertEqual("function", typeof console.assert); |
---|
7 | }, |
---|
8 | |
---|
9 | function getText(t){ |
---|
10 | if(require.getText){ |
---|
11 | var text = require.getText(require.toUrl("dojo/tests/_base/loader/getText.txt")).replace(/\r|\n/g, ""); |
---|
12 | t.assertEqual("dojo._getText() test data", text); |
---|
13 | if(dojo._getText){ |
---|
14 | text = dojo._getText(require.toUrl("dojo/tests/_base/loader/getText.txt")).replace(/\r|\n/g, ""); |
---|
15 | t.assertEqual("dojo._getText() test data", text); |
---|
16 | } |
---|
17 | } |
---|
18 | }, |
---|
19 | |
---|
20 | { |
---|
21 | name: "getObject", |
---|
22 | setUp: function(){ |
---|
23 | //Set an object in global scope. |
---|
24 | dojo.global.globalValue = { |
---|
25 | color: "blue", |
---|
26 | size: 20 |
---|
27 | }; |
---|
28 | |
---|
29 | //Set up an object in a specific scope. |
---|
30 | this.foo = { |
---|
31 | bar: { |
---|
32 | color: "red", |
---|
33 | size: 100 |
---|
34 | } |
---|
35 | }; |
---|
36 | }, |
---|
37 | runTest: function(t){ |
---|
38 | //Test for existing object using global as root path. |
---|
39 | var globalVar = dojo.getObject("globalValue"); |
---|
40 | t.is("object", (typeof globalVar)); |
---|
41 | t.assertEqual("blue", globalVar.color); |
---|
42 | t.assertEqual(20, globalVar.size); |
---|
43 | t.assertEqual("blue", dojo.getObject("globalValue.color")); |
---|
44 | |
---|
45 | //Test for non-existent object using global as root path. |
---|
46 | //Then create it. |
---|
47 | t.assertFalse(dojo.getObject("something.thatisNew")); |
---|
48 | t.assertTrue(typeof(dojo.getObject("something.thatisNew", true)) == "object"); |
---|
49 | |
---|
50 | //Test for existing object using another object as root path. |
---|
51 | var scopedVar = dojo.getObject("foo.bar", false, this); |
---|
52 | t.assertTrue(typeof(scopedVar) == "object"); |
---|
53 | t.assertEqual("red", scopedVar.color); |
---|
54 | t.assertEqual(100, scopedVar.size); |
---|
55 | t.assertEqual("red", dojo.getObject("foo.bar.color", true, this)); |
---|
56 | |
---|
57 | //Test for existing object using another object as root path. |
---|
58 | //Then create it. |
---|
59 | t.assertFalse(dojo.getObject("something.thatisNew", false, this)); |
---|
60 | t.assertTrue(typeof(dojo.getObject("something.thatisNew", true, this)) == "object"); |
---|
61 | }, |
---|
62 | tearDown: function(){ |
---|
63 | //Clean up global object that should not exist if |
---|
64 | //the test is re-run. |
---|
65 | try{ |
---|
66 | delete dojo.global.something; |
---|
67 | delete this.something; |
---|
68 | }catch(e){} |
---|
69 | } |
---|
70 | }, |
---|
71 | |
---|
72 | { |
---|
73 | name: "exists", |
---|
74 | setUp: function(){ |
---|
75 | this.foo = { |
---|
76 | bar: {}, |
---|
77 | baz: 0, |
---|
78 | bam: false, |
---|
79 | bal: "", |
---|
80 | ban: null |
---|
81 | }; |
---|
82 | }, |
---|
83 | runTest: function(t){ |
---|
84 | t.assertTrue(dojo.exists("foo.bar", this)); |
---|
85 | t.assertFalse(dojo.exists("foo.bar")); |
---|
86 | t.assertTrue(dojo.exists("foo.baz", this)); |
---|
87 | t.assertTrue(dojo.exists("foo.bal", this)); |
---|
88 | t.assertTrue(dojo.exists("foo.ban", this)); |
---|
89 | t.assertTrue(dojo.exists("foo.bam", this)); |
---|
90 | t.assertFalse(dojo.exists("foo.bat", this)); |
---|
91 | t.assertTrue(dojo.exists("a.b", { a:{ b:0 }})); |
---|
92 | t.assertFalse(dojo.exists("foo.bar.baz.bam.bap", this)); |
---|
93 | } |
---|
94 | }, |
---|
95 | |
---|
96 | function evalWorks(t){ |
---|
97 | t.assertTrue(dojo.eval("(true)")); |
---|
98 | t.assertFalse(dojo.eval("(false)")); |
---|
99 | if(!has("ie")){ |
---|
100 | // eval truly executes in global scope for non IE |
---|
101 | t.is(window.rawld, undefined); |
---|
102 | dojo.eval("var rawld = 3.14;"); |
---|
103 | t.assertEqual(rawld, 3.14); |
---|
104 | t.assertEqual(window.rawld, 3.14); |
---|
105 | window.rawld = undefined; |
---|
106 | }else{ |
---|
107 | // example of how to compensate for IE |
---|
108 | t.is(window.rawld, undefined); |
---|
109 | dojo.eval("window.rawld = 3.14;"); |
---|
110 | t.assertEqual(rawld, 3.14); |
---|
111 | t.assertEqual(window.rawld, 3.14); |
---|
112 | window.rawld = undefined; |
---|
113 | } |
---|
114 | }, |
---|
115 | |
---|
116 | function _mixin(t){ |
---|
117 | var a = { |
---|
118 | x: 1, |
---|
119 | y: function(){ return 2; }, |
---|
120 | z1: 99, |
---|
121 | w: 2, |
---|
122 | v: undefined |
---|
123 | }; |
---|
124 | var b = { |
---|
125 | x: 11, |
---|
126 | y: function(){ return 12; }, |
---|
127 | z2: 33, |
---|
128 | toString: function(){ return "bark!"; }, |
---|
129 | toLocaleString: function(){ return "le bark-s!"; }, |
---|
130 | w: undefined, |
---|
131 | v: undefined, |
---|
132 | u: undefined |
---|
133 | }; |
---|
134 | t.is(1, a.x); |
---|
135 | t.is(2, a.y()); |
---|
136 | t.is(99, a.z1); |
---|
137 | t.t("w" in a); |
---|
138 | t.is(2, a.w); |
---|
139 | t.t("v" in a); |
---|
140 | t.is(undefined, a.v); |
---|
141 | t.f("u" in a); |
---|
142 | dojo._mixin(a, b); |
---|
143 | t.is(11, a.x); |
---|
144 | t.is(12, a.y()); |
---|
145 | t.is("bark!", a.toString()); |
---|
146 | t.is("le bark-s!", a.toLocaleString()); |
---|
147 | t.is(99, a.z1); |
---|
148 | t.is(33, a.z2); |
---|
149 | t.t("w" in a); |
---|
150 | t.is(undefined, a.w); |
---|
151 | t.t("v" in a); |
---|
152 | t.is(undefined, a.v); |
---|
153 | t.t("u" in a); |
---|
154 | t.is(undefined, a.u); |
---|
155 | } |
---|
156 | ]); |
---|
157 | }); |
---|