Debian Codegraph @

old-tests/tests_onhold/1_dom/_getDataFunctions.js

raw
1 // DATA_TEMPLATE: dom_data
2 oTest.fnStart( "Check behaviour of the data get functions that DataTables uses" );
3
4 $(document).ready( function () {
5 // Slightly unusual test set this one, in that we don't really care about the DOM
6 // but want to test the internal data handling functions but we do need a table to
7 // get at the functions!
8 var table = $('#example').dataTable();
9 var fn, test;
10
11 // Object property access
12 oTest.fnTest(
13 "Single object, single property",
14 function () {
15 fn = table.oApi._fnGetObjectDataFn('test');
16 test = fn( { "test": true } );
17 },
18 function () { return test }
19 );
20
21 oTest.fnTest(
22 "Single property from object",
23 function () {
24 fn = table.oApi._fnGetObjectDataFn('test');
25 test = fn( { "test": true, "test2": false } );
26 },
27 function () { return test }
28 );
29
30 oTest.fnTest(
31 "Single property from object - different property",
32 function () {
33 fn = table.oApi._fnGetObjectDataFn('test2');
34 test = fn( { "test": true, "test2": false } );
35 },
36 function () { return test===false }
37 );
38
39 oTest.fnTest(
40 "Undefined property from object",
41 function () {
42 fn = table.oApi._fnGetObjectDataFn('test3');
43 test = fn( { "test": true, "test2": false } );
44 },
45 function () { return test===undefined }
46 );
47
48 // Array index access
49 oTest.fnTest(
50 "Array access - index 0",
51 function () {
52 fn = table.oApi._fnGetObjectDataFn(0);
53 test = fn( [true, false, false, false] );
54 },
55 function () { return test }
56 );
57
58 oTest.fnTest(
59 "Array access - index 1",
60 function () {
61 fn = table.oApi._fnGetObjectDataFn(2);
62 test = fn( [false, false, true, false] );
63 },
64 function () { return test }
65 );
66
67 oTest.fnTest(
68 "Array access - undefined",
69 function () {
70 fn = table.oApi._fnGetObjectDataFn(7);
71 test = fn( [false, false, true, false] );
72 },
73 function () { return test===undefined }
74 );
75
76 // null source
77 oTest.fnTest(
78 "null source",
79 function () {
80 fn = table.oApi._fnGetObjectDataFn( null );
81 tmp = [false, false, true, false];
82 test = fn( tmp );
83 },
84 function () { return test===tmp }
85 );
86
87 // nested objects
88 oTest.fnTest(
89 "Nested object property",
90 function () {
91 fn = table.oApi._fnGetObjectDataFn( 'a.b' );
92 test = fn( {
93 "a":{
94 "b": true,
95 "c": false,
96 "d": 1
97 }
98 } );
99 },
100 function () { return test }
101 );
102
103 oTest.fnTest(
104 "Nested object property - different prop",
105 function () {
106 fn = table.oApi._fnGetObjectDataFn( 'a.d' );
107 test = fn( {
108 "a":{
109 "b": true,
110 "c": false,
111 "d": 1
112 }
113 } );
114 },
115 function () { return test===1 }
116 );
117
118 oTest.fnTest(
119 "Nested object property - undefined prop",
120 function () {
121 fn = table.oApi._fnGetObjectDataFn( 'a.z' );
122 test = fn( {
123 "a":{
124 "b": true,
125 "c": false,
126 "d": 1
127 }
128 } );
129 },
130 function () { return test===undefined }
131 );
132
133 // Nested array
134 oTest.fnTest(
135 "Nested array index property",
136 function () {
137 fn = table.oApi._fnGetObjectDataFn( 'a.0' );
138 test = fn( {
139 "a": [
140 true,
141 false,
142 1
143 ]
144 } );
145 },
146 function () { return test }
147 );
148
149 oTest.fnTest(
150 "Nested array index property - different index",
151 function () {
152 fn = table.oApi._fnGetObjectDataFn( 'a.2' );
153 test = fn( {
154 "a": [
155 true,
156 false,
157 1
158 ]
159 } );
160 },
161 function () { return test===1 }
162 );
163
164 oTest.fnTest(
165 "Nested array index property - undefined index",
166 function () {
167 fn = table.oApi._fnGetObjectDataFn( 'a.10' );
168 test = fn( {
169 "a": [
170 true,
171 false,
172 1
173 ]
174 } );
175 },
176 function () { return test===undefined }
177 );
178
179 // Nested array object property
180 oTest.fnTest(
181 "Nested array index object property",
182 function () {
183 fn = table.oApi._fnGetObjectDataFn( 'a.0.m' );
184 test = fn( {
185 "a": [
186 { "m": true, "n": 1 },
187 { "m": false, "n": 2 },
188 { "m": false, "n": 3 }
189 ]
190 } );
191 },
192 function () { return test }
193 );
194
195 oTest.fnTest(
196 "Nested array index object property - different index",
197 function () {
198 fn = table.oApi._fnGetObjectDataFn( 'a.2.n' );
199 test = fn( {
200 "a": [
201 { "m": true, "n": 1 },
202 { "m": false, "n": 2 },
203 { "m": false, "n": 3 }
204 ]
205 } );
206 },
207 function () { return test===3 }
208 );
209
210 oTest.fnTest(
211 "Nested array index object property - undefined index",
212 function () {
213 fn = table.oApi._fnGetObjectDataFn( 'a.0.z' );
214 test = fn( {
215 "a": [
216 { "m": true, "n": 1 },
217 { "m": false, "n": 2 },
218 { "m": false, "n": 3 }
219 ]
220 } );
221 },
222 function () { return test===undefined }
223 );
224
225 // Array notation - no join
226 oTest.fnTest(
227 "Array notation - no join - property",
228 function () {
229 fn = table.oApi._fnGetObjectDataFn( 'a[].n' );
230 test = fn( {
231 "a": [
232 { "m": true, "n": 1 },
233 { "m": false, "n": 2 },
234 { "m": false, "n": 3 }
235 ]
236 } );
237 },
238 function () {
239 return test.length===3 && test[0]===1
240 && test[1]===2 && test[2]===3;
241 }
242 );
243
244 oTest.fnTest(
245 "Array notation - no join - property (2)",
246 function () {
247 fn = table.oApi._fnGetObjectDataFn( 'a[].m' );
248 test = fn( {
249 "a": [
250 { "m": true, "n": 1 },
251 { "m": false, "n": 2 }
252 ]
253 } );
254 },
255 function () {
256 return test.length===2 && test[0]===true
257 && test[1]===false;
258 }
259 );
260
261 oTest.fnTest(
262 "Array notation - no join - undefined property",
263 function () {
264 fn = table.oApi._fnGetObjectDataFn( 'a[].z' );
265 test = fn( {
266 "a": [
267 { "m": true, "n": 1 },
268 { "m": false, "n": 2 }
269 ]
270 } );
271 },
272 function () {
273 return test.length===2 && test[0]===undefined
274 && test[1]===undefined;
275 }
276 );
277
278 // Array notation - join
279 oTest.fnTest(
280 "Array notation - space join - property",
281 function () {
282 fn = table.oApi._fnGetObjectDataFn( 'a[ ].n' );
283 test = fn( {
284 "a": [
285 { "m": true, "n": 1 },
286 { "m": false, "n": 2 },
287 { "m": false, "n": 3 }
288 ]
289 } );
290 },
291 function () { return test === '1 2 3'; }
292 );
293
294 oTest.fnTest(
295 "Array notation - space join - property (2)",
296 function () {
297 fn = table.oApi._fnGetObjectDataFn( 'a[ ].m' );
298 test = fn( {
299 "a": [
300 { "m": true, "n": 1 },
301 { "m": false, "n": 2 }
302 ]
303 } );
304 },
305 function () { return test === 'true false'; }
306 );
307
308 oTest.fnTest(
309 "Array notation - sapce join - undefined property",
310 function () {
311 fn = table.oApi._fnGetObjectDataFn( 'a[ ].z' );
312 test = fn( {
313 "a": [
314 { "m": true, "n": 1 },
315 { "m": false, "n": 2 }
316 ]
317 } );
318 },
319 function () { return test === ' '; }
320 );
321 oTest.fnTest(
322 "Array notation - string join - property",
323 function () {
324 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty].n' );
325 test = fn( {
326 "a": [
327 { "m": true, "n": 1 },
328 { "m": false, "n": 2 },
329 { "m": false, "n": 3 }
330 ]
331 } );
332 },
333 function () { return test === '1qwerty2qwerty3'; }
334 );
335
336 oTest.fnTest(
337 "Array notation - string join - property (2)",
338 function () {
339 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty].m' );
340 test = fn( {
341 "a": [
342 { "m": true, "n": 1 },
343 { "m": false, "n": 2 }
344 ]
345 } );
346 },
347 function () { return test === 'trueqwertyfalse'; }
348 );
349
350 // Array alone join
351 oTest.fnTest(
352 "Flat array join",
353 function () {
354 fn = table.oApi._fnGetObjectDataFn( 'a[ ]' );
355 test = fn( {
356 "a": [
357 true,
358 false,
359 1
360 ]
361 } );
362 },
363 function () { return test==="true false 1"; }
364 );
365
366 oTest.fnTest(
367 "Flat array string join",
368 function () {
369 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty]' );
370 test = fn( {
371 "a": [
372 true,
373 false,
374 1
375 ]
376 } );
377 },
378 function () { return test==="trueqwertyfalseqwerty1"; }
379 );
380
381 oTest.fnTest(
382 "Flat array no join",
383 function () {
384 fn = table.oApi._fnGetObjectDataFn( 'a[]' );
385 test = fn( {
386 "a": [
387 true,
388 false,
389 1
390 ]
391 } );
392 },
393 function () { return test.length===3 && test[0]===true &&
394 test[1]===false && test[2]===1; }
395 );
396
397
398
399 oTest.fnComplete();
400 } );