1 // DATA_TEMPLATE: dom_data
2 oTest.fnStart( "Check behaviour of the data get functions that DataTables uses" );
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();
11 // Object property access
13 "Single object, single property",
15 fn = table.oApi._fnGetObjectDataFn('test');
16 test = fn( { "test": true } );
18 function () { return test }
22 "Single property from object",
24 fn = table.oApi._fnGetObjectDataFn('test');
25 test = fn( { "test": true, "test2": false } );
27 function () { return test }
31 "Single property from object - different property",
33 fn = table.oApi._fnGetObjectDataFn('test2');
34 test = fn( { "test": true, "test2": false } );
36 function () { return test===false }
40 "Undefined property from object",
42 fn = table.oApi._fnGetObjectDataFn('test3');
43 test = fn( { "test": true, "test2": false } );
45 function () { return test===undefined }
50 "Array access - index 0",
52 fn = table.oApi._fnGetObjectDataFn(0);
53 test = fn( [true, false, false, false] );
55 function () { return test }
59 "Array access - index 1",
61 fn = table.oApi._fnGetObjectDataFn(2);
62 test = fn( [false, false, true, false] );
64 function () { return test }
68 "Array access - undefined",
70 fn = table.oApi._fnGetObjectDataFn(7);
71 test = fn( [false, false, true, false] );
73 function () { return test===undefined }
80 fn = table.oApi._fnGetObjectDataFn( null );
81 test = fn( [false, false, true, false] );
83 function () { return test===null }
88 "Nested object property",
90 fn = table.oApi._fnGetObjectDataFn( 'a.b' );
99 function () { return test }
103 "Nested object property - different prop",
105 fn = table.oApi._fnGetObjectDataFn( 'a.d' );
114 function () { return test===1 }
118 "Nested object property - undefined prop",
120 fn = table.oApi._fnGetObjectDataFn( 'a.z' );
129 function () { return test===undefined }
134 "Nested array index property",
136 fn = table.oApi._fnGetObjectDataFn( 'a.0' );
145 function () { return test }
149 "Nested array index property - different index",
151 fn = table.oApi._fnGetObjectDataFn( 'a.2' );
160 function () { return test===1 }
164 "Nested array index property - undefined index",
166 fn = table.oApi._fnGetObjectDataFn( 'a.10' );
175 function () { return test===undefined }
178 // Nested array object property
180 "Nested array index object property",
182 fn = table.oApi._fnGetObjectDataFn( 'a.0.m' );
185 { "m": true, "n": 1 },
186 { "m": false, "n": 2 },
187 { "m": false, "n": 3 }
191 function () { return test }
195 "Nested array index object property - different index",
197 fn = table.oApi._fnGetObjectDataFn( 'a.2.n' );
200 { "m": true, "n": 1 },
201 { "m": false, "n": 2 },
202 { "m": false, "n": 3 }
206 function () { return test===3 }
210 "Nested array index object property - undefined index",
212 fn = table.oApi._fnGetObjectDataFn( 'a.0.z' );
215 { "m": true, "n": 1 },
216 { "m": false, "n": 2 },
217 { "m": false, "n": 3 }
221 function () { return test===undefined }
224 // Array notation - no join
226 "Array notation - no join - property",
228 fn = table.oApi._fnGetObjectDataFn( 'a[].n' );
231 { "m": true, "n": 1 },
232 { "m": false, "n": 2 },
233 { "m": false, "n": 3 }
238 return test.length===3 && test[0]===1
239 && test[1]===2 && test[2]===3;
244 "Array notation - no join - property (2)",
246 fn = table.oApi._fnGetObjectDataFn( 'a[].m' );
249 { "m": true, "n": 1 },
250 { "m": false, "n": 2 }
255 return test.length===2 && test[0]===true
261 "Array notation - no join - undefined property",
263 fn = table.oApi._fnGetObjectDataFn( 'a[].z' );
266 { "m": true, "n": 1 },
267 { "m": false, "n": 2 }
272 return test.length===2 && test[0]===undefined
273 && test[1]===undefined;
277 // Array notation - join
279 "Array notation - space join - property",
281 fn = table.oApi._fnGetObjectDataFn( 'a[ ].n' );
284 { "m": true, "n": 1 },
285 { "m": false, "n": 2 },
286 { "m": false, "n": 3 }
290 function () { return test === '1 2 3'; }
294 "Array notation - space join - property (2)",
296 fn = table.oApi._fnGetObjectDataFn( 'a[ ].m' );
299 { "m": true, "n": 1 },
300 { "m": false, "n": 2 }
304 function () { return test === 'true false'; }
308 "Array notation - sapce join - undefined property",
310 fn = table.oApi._fnGetObjectDataFn( 'a[ ].z' );
313 { "m": true, "n": 1 },
314 { "m": false, "n": 2 }
318 function () { return test === ' '; }
321 "Array notation - string join - property",
323 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty].n' );
326 { "m": true, "n": 1 },
327 { "m": false, "n": 2 },
328 { "m": false, "n": 3 }
332 function () { return test === '1qwerty2qwerty3'; }
336 "Array notation - string join - property (2)",
338 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty].m' );
341 { "m": true, "n": 1 },
342 { "m": false, "n": 2 }
346 function () { return test === 'trueqwertyfalse'; }
353 fn = table.oApi._fnGetObjectDataFn( 'a[ ]' );
362 function () { return test==="true false 1"; }
366 "Flat array string join",
368 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty]' );
377 function () { return test==="trueqwertyfalseqwerty1"; }
381 "Flat array no join",
383 fn = table.oApi._fnGetObjectDataFn( 'a[]' );
392 function () { return test.length===3 && test[0]===true &&
393 test[1]===false && test[2]===1; }