datasource.html
23.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<html>
<head>
<title>YUI DataSource Tests</title>
<link type="text/css" rel="stylesheet" href="../build/logger/assets/skins/sam/logger.css" />
<link type="text/css" rel="stylesheet" href="../build/yuitest/assets/testlogger.css" />
<style type="text/css">
.yui-skin-sam .yui-log {
padding: 2.5em 1em 1em;
height: 90%;
}
.yui-skin-sam .yui-log .yui-log-bd {
width: auto;
height: 100%;
}
</style>
</head>
<body class="yui-skin-sam">
<h1>DataSource Tests</h1>
<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
<script type="text/javascript" src="../build/yahoo/yahoo.js"></script>
<script type="text/javascript" src="../build/dom/dom.js"></script>
<script type="text/javascript" src="../build/event/event.js"></script>
<script type="text/javascript" src="../build/logger/logger.js"></script>
<script type="text/javascript" src="../build/yuitest/yuitest.js"></script>
<script type="text/javascript" src="../build/json/json.js"></script>
<script type="text/javascript" src="../build/datasource/datasource-beta-debug.js"></script>
<script type="text/javascript">
(function() {
var Dom=YAHOO.util.Dom,
Assert=YAHOO.util.Assert,
ObjectAssert=YAHOO.util.ObjectAssert,
ArrayAssert=YAHOO.util.ArrayAssert,
DateAssert=YAHOO.util.DateAssert,
UserAction=YAHOO.util.UserAction,
TestCase = YAHOO.tool.TestCase,
TestLogger = YAHOO.tool.TestLogger,
TestRunner = YAHOO.tool.TestRunner,
TestSuite = YAHOO.tool.TestSuite,
lang = YAHOO.lang,
DataSource = YAHOO.util.DataSource;
// Create utility function for pass-by-ref + reuse errors
var cloneObject = function(o) {
if (lang.isArray(o)) {
var a = [];
for (var i=0,l=o.length;i<l;i++) {
a[i] = cloneObject(o[i]);
}
return a;
} else if (typeof o === 'object' && o) {
var c = {};
for (var x in o) {
if (lang.hasOwnProperty(o, x)) {
c[x] = cloneObject(o[x]);
}
}
return c;
}
else {
return o;
}
}
/**
*
*
* Base DataSource test case.
*
*
*/
function DataSourceTestCase(template) {
DataSourceTestCase.superclass.constructor.call(this, template);
this.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
};
YAHOO.lang.extend(DataSourceTestCase, TestCase);
DataSourceTestCase.prototype.setUp = function() {
};
DataSourceTestCase.prototype.tearDown = function() {
};
DataSourceTestCase.prototype.createInstance = function(oConfigs) {
ds = new DataSource((cloneObject(this.data)||["a","b","c"]), oConfigs);
ds.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
ds.responseSchema = {
fields: ["a","b","c"]
};
return ds;
};
/**
*
*
* Base DataSource test template. Sets up values for a DataSource instance.
*
*
*/
var datasourceTemplate = {
name: "DataSource Test",
testConstruction: function() {
var ds = this.createInstance();
Assert.isObject(ds, "Failed to create instance");
Assert.isInstanceOf(DataSource, ds, "Failed to create instance");
ds = null;
}
};
var datasourceTest = new DataSourceTestCase(datasourceTemplate);
/**
*
*
* Tests array of JS objects.
*
*
*/
var dsComplexArrayTemplate = YAHOO.lang.merge(datasourceTemplate, {
name:"Complex Array Test",
data:[{a:"1a",b:"1b",c:"1c"}, {a:"2a",b:"2b",c:"2c"}, {a:"3a",b:"3b",c:"3c"}]
});
var dsComplexArrayTest = new DataSourceTestCase(dsComplexArrayTemplate);
/**
*
*
* Tests DataSource Cache.
*
*
*/
var dsCacheTemplate = {
name: "Cache Test",
testDefault: function() {
var ds = this.createInstance();
Assert.areSame(null, ds._aCache, "Failed to NOT init cache (default)");
ds = null;
},
testViaConfig: function() {
var ds = this.createInstance({maxCacheEntries:5});
Assert.areSame(null, ds._aCache, "Cache should not be initialized yet");
ds.sendRequest("a", function() {
Assert.areSame(true, YAHOO.lang.isArray(ds._aCache), "Failed to init cache (via constructor)");
Assert.areSame(1, ds._aCache.length, "Cache should have one item");
ds.flushCache();
Assert.areSame(0, ds._aCache.length, "Cache should be empty");
ds = null;
});
},
testViaProperty: function() {
var ds = this.createInstance();
ds.maxCacheEntries = 5;
ds.sendRequest("a", function() {
Assert.areSame(true, YAHOO.lang.isArray(ds._aCache), "Failed to init cache (via property)");
Assert.areSame(1, ds._aCache.length, "Cache should have one item");
ds.maxCacheEntries = 0;
Assert.areSame(1, ds._aCache.length, "Cache should still have one item");
ds.sendRequest("a", function() {
Assert.areSame(null, ds._aCache, "Cache should be destroyed");
ds = null;
});
});
}
};
var dsCacheTest = new DataSourceTestCase(dsCacheTemplate);
/**
*
*
* Tests XHR.
*
*
*/
var dsXHRTemplate = YAHOO.lang.merge(datasourceTemplate, {
name:"XHR Test",
data:"path/to/proxy"
});
var dsXHRTest = new DataSourceTestCase(dsXHRTemplate);
/**
*
*
* Tests JSON parsing.
*
*
*/
var dsParseJSONTemplate = YAHOO.lang.merge(datasourceTemplate, {
name:"Parse JSON Test",
data: {"ResultSet":{
"totalResultsAvailable":506,
"totalResultsReturned":10,
"first Result Position":1,
"ResultSetMapUrl":"http:\/\/maps.yahoo.com\/broadband\/?q1=Sunnyvale%2C+CA+94089&tt=pizza&tp=1",
"Result":[
{Title:"Giovannis Pizzeria",MyArray:["1127 N Lawrence Expy"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[408,734,4221],"for":"37.397058","Longitude":"-121.996017","Nested":{"Average-Rating":"4","Total Ratings":"54","TotalReviews":"36",MyArray:["1201994139"]},"Distance":"0.62","Url":"http:\/\/local.yahoo.com\/details?id=21341983&stx=pizza&csz=Sunnyvale+CA&ed=MKz.rq160SwrCmnpe6IIB6SO8HQ4zpqeQiusehO32jPu0kFQONfQkxJV87YlenT7OdxlEDHPoHfJqkjm","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21341983&stx=pizza&csz=Sunnyvale+CA&ed=MKz.rq160SwrCmnpe6IIB6SO8HQ4zpqeQiusehO32jPu0kFQONfQkxJV87YlenT7OdxlEDHPoHfJqkjm","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Giovannis+Pizzeria&desc=4087344221&csz=Sunnyvale+CA&qty=9&cs=9&ed=MKz.rq160SwrCmnpe6IIB6SO8HQ4zpqeQiusehO32jPu0kFQONfQkxJV87YlenT7OdxlEDHPoHfJqkjm&gid1=21341983","BusinessUrl":"","BusinessClickUrl":""},
{Title:"Gumbas Cafe Italian Restaurant & Pizzeria",MyArray:["176 S Murphy Ave"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[408,737,8384],"for":"37.376442","Longitude":"-122.030102","Nested":{"Average-Rating":"4","Total Ratings":"38","TotalReviews":"26",MyArray:["1199489524"]},"Distance":"2.05","Url":"http:\/\/local.yahoo.com\/details?id=21337886&stx=pizza&csz=Sunnyvale+CA&ed=uj7cXq160SxhJq9XTxZy.yXDsYz0FRBPkLX2zpjvEH6o4FWX9XPNxDcQ6y3QcRkD8A_GfKyDEVY-","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21337886&stx=pizza&csz=Sunnyvale+CA&ed=uj7cXq160SxhJq9XTxZy.yXDsYz0FRBPkLX2zpjvEH6o4FWX9XPNxDcQ6y3QcRkD8A_GfKyDEVY-","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Gumbas+Cafe+Italian+Restaurant+%26+Pizzeria&desc=4087378384&csz=Sunnyvale+CA&qty=9&cs=9&ed=uj7cXq160SxhJq9XTxZy.yXDsYz0FRBPkLX2zpjvEH6o4FWX9XPNxDcQ6y3QcRkD8A_GfKyDEVY-&gid1=21337886","BusinessUrl":"","BusinessClickUrl":""},
{Title:"Vitos Famous Pizza",MyArray:["1155 Reed Ave"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[(408),246,8800],"for":"37.367029","Longitude":"-121.997904","Nested":{"Average-Rating":"4.5","Total Ratings":"16","TotalReviews":"13",MyArray:["1195089220"]},"Distance":"2.30","Url":"http:\/\/local.yahoo.com\/details?id=21332026&stx=pizza&csz=Sunnyvale+CA&ed=N38lFq160SymmdPNQF8OuFWLoPx_i.6GZDIVFehy9mWH6xbhRaqIfTx6ts8pKvY20AnKblM-","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21332026&stx=pizza&csz=Sunnyvale+CA&ed=N38lFq160SymmdPNQF8OuFWLoPx_i.6GZDIVFehy9mWH6xbhRaqIfTx6ts8pKvY20AnKblM-","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Vitos+Famous+Pizza&desc=4082468800&csz=Sunnyvale+CA&qty=9&cs=9&ed=N38lFq160SymmdPNQF8OuFWLoPx_i.6GZDIVFehy9mWH6xbhRaqIfTx6ts8pKvY20AnKblM-&gid1=21332026","BusinessUrl":"http:\/\/vitosfamouspizza.com\/","BusinessClickUrl":"http:\/\/vitosfamouspizza.com\/"},
{Title:"Domino's Pizza",MyArray:["615 Caliente Dr"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[(408), 732,3030],"for":"37.391271","Longitude":"-122.013742","Nested":{"Average-Rating":"4","Total Ratings":"5","TotalReviews":"0",MyArray:["1195089222"]},"Distance":"0.81","Url":"http:\/\/local.yahoo.com\/details?id=21335892&stx=pizza&csz=Sunnyvale+CA&ed=8AfC_K160Sxfwh8iare3qmr9FJ3PN3F1hAEsxLQGY7jUiik2FpVQoHyE7foPhoqHownL0ORw2A--","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21335892&stx=pizza&csz=Sunnyvale+CA&ed=8AfC_K160Sxfwh8iare3qmr9FJ3PN3F1hAEsxLQGY7jUiik2FpVQoHyE7foPhoqHownL0ORw2A--","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Domino%27s+Pizza&desc=4087323030&csz=Sunnyvale+CA&qty=9&cs=9&ed=8AfC_K160Sxfwh8iare3qmr9FJ3PN3F1hAEsxLQGY7jUiik2FpVQoHyE7foPhoqHownL0ORw2A--&gid1=21335892","BusinessUrl":"http:\/\/www.dominos.com\/","BusinessClickUrl":"http:\/\/www.dominos.com\/"},
{Title:"Domino's Pizza",MyArray:["992 W El Camino Real"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[(408),736,3666],"for":"37.371434","Longitude":"-122.047559","Nested":{"Average-Rating":"4","Total Ratings":"7","TotalReviews":"3",MyArray:["1127363766"]},"Distance":"2.80","Url":"http:\/\/local.yahoo.com\/details?id=21341882&stx=pizza&csz=Sunnyvale+CA&ed=q0udl6160Sx.AqTKVZbNw3XSw.U4VT.yixioJ6k.H7cOEZSOqMOl7Kf6Mc21zYe1tziGcwBKEW9HzCfs","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21341882&stx=pizza&csz=Sunnyvale+CA&ed=q0udl6160Sx.AqTKVZbNw3XSw.U4VT.yixioJ6k.H7cOEZSOqMOl7Kf6Mc21zYe1tziGcwBKEW9HzCfs","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Domino%27s+Pizza&desc=4087363666&csz=Sunnyvale+CA&qty=9&cs=9&ed=q0udl6160Sx.AqTKVZbNw3XSw.U4VT.yixioJ6k.H7cOEZSOqMOl7Kf6Mc21zYe1tziGcwBKEW9HzCfs&gid1=21341882","BusinessUrl":"http:\/\/www.dominos.com\/","BusinessClickUrl":"http:\/\/www.dominos.com\/"},
{Title:"Pizza Depot",MyArray:["919 E Duane Ave"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[(408),245,7760],"for":"37.388527","Longitude":"-122.004046","Nested":{"Average-Rating":"3.5","Total Ratings":"6","TotalReviews":"5",MyArray:["1161370760"]},"Distance":"0.93","Url":"http:\/\/local.yahoo.com\/details?id=21332021&stx=pizza&csz=Sunnyvale+CA&ed=7KK7mK160SzRB7AzH1MQcGzaJtl1F1AhRiRj3iKI5XIyMK5AKtQ2d5fqhwSD1KvtPBjDptclVg--","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21332021&stx=pizza&csz=Sunnyvale+CA&ed=7KK7mK160SzRB7AzH1MQcGzaJtl1F1AhRiRj3iKI5XIyMK5AKtQ2d5fqhwSD1KvtPBjDptclVg--","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Pizza+Depot&desc=4082457760&csz=Sunnyvale+CA&qty=9&cs=9&ed=7KK7mK160SzRB7AzH1MQcGzaJtl1F1AhRiRj3iKI5XIyMK5AKtQ2d5fqhwSD1KvtPBjDptclVg--&gid1=21332021","BusinessUrl":"http:\/\/pizza-depot.com\/","BusinessClickUrl":"http:\/\/pizza-depot.com\/"},
{Title:"Round Table Pizza Sunnyvale",MyArray:["665 S Bernardo Ave"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[(408),732,6670],"for":"37.372847","Longitude":"-122.056805","Nested":{"Average-Rating":"4","Total Ratings":"2","TotalReviews":"2",MyArray:["1186612286"]},"Distance":"3.05","Url":"http:\/\/local.yahoo.com\/details?id=21328190&stx=pizza&csz=Sunnyvale+CA&ed=7UuQPq160SyTLgsCywr8RVh7QMTEamkpxTk1eEvusFf6qe0s4ZWcRmYd.2M0jmVjLcEFk_Gf1v10hg--","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21328190&stx=pizza&csz=Sunnyvale+CA&ed=7UuQPq160SyTLgsCywr8RVh7QMTEamkpxTk1eEvusFf6qe0s4ZWcRmYd.2M0jmVjLcEFk_Gf1v10hg--","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Round+Table+Pizza+Sunnyvale&desc=4087326670&csz=Sunnyvale+CA&qty=9&cs=9&ed=7UuQPq160SyTLgsCywr8RVh7QMTEamkpxTk1eEvusFf6qe0s4ZWcRmYd.2M0jmVjLcEFk_Gf1v10hg--&gid1=21328190","BusinessUrl":"http:\/\/www.roundtablepizza.com\/","BusinessClickUrl":"http:\/\/www.roundtablepizza.com\/"},
{Title:"Big Bite Pizza",MyArray:["109 E Fremont Ave"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[(408),481,0666],"for":"37.352338","Longitude":"-122.031861","Nested":{"Average-Rating":"4","Total Ratings":"4","TotalReviews":"2",MyArray:["1190777914"]},"Distance":"3.42","Url":"http:\/\/local.yahoo.com\/details?id=25660586&stx=pizza&csz=Sunnyvale+CA&ed=XUNURa160SwU43kPscbu1nhShMQE1ZF7Bnnh8qSivRQ4ASxOcRXUml7KMN.4QoLsYF0xn5KhnpoW","ClickUrl":"http:\/\/local.yahoo.com\/details?id=25660586&stx=pizza&csz=Sunnyvale+CA&ed=XUNURa160SwU43kPscbu1nhShMQE1ZF7Bnnh8qSivRQ4ASxOcRXUml7KMN.4QoLsYF0xn5KhnpoW","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Big+Bite+Pizza&desc=4084810666&csz=Sunnyvale+CA&qty=9&cs=9&ed=XUNURa160SwU43kPscbu1nhShMQE1ZF7Bnnh8qSivRQ4ASxOcRXUml7KMN.4QoLsYF0xn5KhnpoW&gid1=25660586","BusinessUrl":"","BusinessClickUrl":""},
{Title:"Pizza Hut",MyArray:["464 N Mathilda Ave"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[(408),735,1900],"for":"37.388298","Longitude":"-122.03056","Nested":{"Average-Rating":"2.5","Total Ratings":"8","TotalReviews":"5",MyArray:["1195096424"]},"Distance":"1.49","Url":"http:\/\/local.yahoo.com\/details?id=21340811&stx=pizza&csz=Sunnyvale+CA&ed=fg.eBq160Sw0QwGltksNXPMtnWxCI0URPWb4E5ZutY7RPm_Jjd5xK395KtaeM7l1A_hYAS0FkNn4","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21340811&stx=pizza&csz=Sunnyvale+CA&ed=fg.eBq160Sw0QwGltksNXPMtnWxCI0URPWb4E5ZutY7RPm_Jjd5xK395KtaeM7l1A_hYAS0FkNn4","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Pizza+Hut&desc=4087351900&csz=Sunnyvale+CA&qty=9&cs=9&ed=fg.eBq160Sw0QwGltksNXPMtnWxCI0URPWb4E5ZutY7RPm_Jjd5xK395KtaeM7l1A_hYAS0FkNn4&gid1=21340811","BusinessUrl":"http:\/\/www.pizzahut.com\/","BusinessClickUrl":"http:\/\/www.pizzahut.com\/"},
{Title:"Round Table Pizza",MyArray:["415 N Mary Ave"],"Hy-phenated":"Sunnyvale","State":"CA","Array Index":[(408),733,1365],"for":"37.390247","Longitude":"-122.041498","Nested":{"Average-Rating":"2.5","Total Ratings":"5","TotalReviews":"2",MyArray:["1155195814"]},"Distance":"1.86","Url":"http:\/\/local.yahoo.com\/details?id=21329046&stx=pizza&csz=Sunnyvale+CA&ed=uyby8a160Sy9qe0i.PcxDTgLyA.E934puXrbc.yiwzLvQHghOQRbey19BpfYd2SdELp9wnqw","ClickUrl":"http:\/\/local.yahoo.com\/details?id=21329046&stx=pizza&csz=Sunnyvale+CA&ed=uyby8a160Sy9qe0i.PcxDTgLyA.E934puXrbc.yiwzLvQHghOQRbey19BpfYd2SdELp9wnqw","MapUrl":"http:\/\/maps.yahoo.com\/maps_result?name=Round+Table+Pizza&desc=4087331365&csz=Sunnyvale+CA&qty=9&cs=9&ed=uyby8a160Sy9qe0i.PcxDTgLyA.E934puXrbc.yiwzLvQHghOQRbey19BpfYd2SdELp9wnqw&gid1=21329046","BusinessUrl":"http:\/\/www.roundtablepizza.com\/","BusinessClickUrl":"http:\/\/www.roundtablepizza.com\/"}
]
}},
testSchemaSyntaxes: function() {
var ds = this.createInstance();
ds.responseType = YAHOO.util.DataSource.TYPE_JSON;
// Simple shema
ds.responseSchema = {
resultsList: "ResultSet.Result",
fields: ["Title","MyArray[0]","Hy-phenated","Array Index","for"]
};
var oCallback = {
success:function(oRequest, oResponse, oPayload) {
Assert.areSame(this.data.ResultSet.Result[9]["Title"], oResponse.results[9]["Title"], "Incorrect parsing of String");
Assert.areSame(this.data.ResultSet.Result[9]["MyArray"][0], oResponse.results[9]["MyArray[0]"], "Incorrect parsing of Array index");
Assert.areSame(this.data.ResultSet.Result[9]["for"], oResponse.results[9]["for"], "Incorrect parsing of reserved word");
// Verify invalids didn't parse
Assert.isUndefined(oResponse.results[9]["Hy-phenated"], "Incorrect parsing of invalid dot syntax key with dash");
Assert.isUndefined(oResponse.results[9]["Array Index"], "Incorrect parsing of invalid dot syntax key with empty space");
},
scope:this
};
ds.sendRequest(null,oCallback);
// Nested schema
ds.responseSchema.fields = ["Nested.TotalReviews","Nested.Average-Rating","Nested.Total Ratings","Nested.MyArray[0]"];
var oCallback = {
success:function(oRequest, oResponse, oPayload) {
Assert.areSame(this.data.ResultSet.Result[9]["Nested"]["TotalReviews"], oResponse.results[9]["Nested.TotalReviews"], "Incorrect parsing of nested String");
ArrayAssert.itemsAreSame(this.data.ResultSet.Result[9]["Nested"]["MyArray"][0], oResponse.results[9]["Nested.MyArray[0]"], "Incorrect parsing of nested Array index");
// Verify invalids didn't parse
Assert.isUndefined(oResponse.results[9]["Nested.Average-Rating"], "Incorrect parsing of invalid nested key containing hyphen");
Assert.isUndefined(oResponse.results[9]["Nested.Total Ratings"], "Incorrect parsing of invalid dot syntax key containing empty space");
},
scope:this
};
ds.sendRequest(null,oCallback);
}
});
var dsParseJSONTest = new DataSourceTestCase(dsParseJSONTemplate);
/**
*
*
* Tests static methods.
*
*
*/
var dsStaticMethodsTemplate = {
name:"Static Methods Test",
data:["a","b","c"],
testParseNumbers: function() {
var number;
var ds = this.createInstance();
var myNumber = 1;
number = YAHOO.util.DataSource.parseNumber("1");
Assert.areSame(number, myNumber, "Incorrect number from String.");
number = YAHOO.util.DataSource.parseNumber(1);
Assert.areSame(number, myNumber, "Incorrect number from Number.");
ds = null;
},
testParseDates: function() {
var date;
var ds = this.createInstance();
var myDate = new Date(2001,0,14); // January 14, 2001
date = YAHOO.util.DataSource.parseDate("1/14/2001");
DateAssert.datesAreEqual(date, myDate, "Incorrect date from String.");
date = YAHOO.util.DataSource.parseDate(myDate);
DateAssert.datesAreEqual(date, myDate, "Incorrect date from Date");
date = YAHOO.util.DataSource.parseDate(979459200000);
DateAssert.datesAreEqual(date, myDate, "Incorrect date from Number.");
ds = null;
}
};
var dsStaticMethodsTest = new DataSourceTestCase(dsStaticMethodsTemplate);
/**
*
*
* Base test case for YAHOO.util.DataType APIs.
*
*
*/
function DataUtilTestCase(template) {
DataUtilTestCase.superclass.constructor.call(this, template);
};
YAHOO.lang.extend(DataUtilTestCase, TestCase);
DataUtilTestCase.prototype.setUp = function() {
};
DataUtilTestCase.prototype.tearDown = function() {
};
/**
*
*
* Tests YAHOO.util.Number APIs.
*
*
*/
var dataNumberTemplate = {
name:"Util Number Test",
testFormat: function() {
output = YAHOO.util.Number.format("1");
Assert.areSame("1", output, "Incorrect output from String.");
output = YAHOO.util.Number.format(1);
Assert.areSame("1", output, "Incorrect output from Number.");
output = YAHOO.util.Number.format(0);
Assert.areSame("0", output, "Incorrect output from zero.");
output = YAHOO.util.Number.format(-1);
Assert.areSame("-1", output, "Incorrect output from negative Number.");
output = YAHOO.util.Number.format(123, {prefix:"$"});
Assert.areSame("$123", output, "Incorrect prefix");
output = YAHOO.util.Number.format(123, {suffix:" items"});
Assert.areSame("123 items", output, "Incorrect suffix");
output = YAHOO.util.Number.format(123.123, {decimalPlaces:5});
Assert.areSame("123.12300", output, "Incorrect decimal rounding: expected 5 places");
output = YAHOO.util.Number.format(123, {decimalPlaces:5});
Assert.areSame("123.00000", output, "Incorrect decimal padding: expected 5 places");
output = YAHOO.util.Number.format(123.123, {decimalPlaces:4});
Assert.areSame("123.1230", output, "Incorrect decimal rounding: expected 4 places");
output = YAHOO.util.Number.format(123.123, {decimalPlaces:3});
Assert.areSame("123.123", output, "Incorrect decimal rounding: expected 3 places");
output = YAHOO.util.Number.format(123.127, {decimalPlaces:2});
Assert.areSame("123.13", output, "Incorrect decimal rounding: expected rounded to 2 places");
output = YAHOO.util.Number.format(123.123, {decimalPlaces:2});
Assert.areSame("123.12", output, "Incorrect decimal rounding: expected 2 places");
output = YAHOO.util.Number.format(123.123, {decimalPlaces:1});
Assert.areSame("123.1", output, "Incorrect decimal rounding: expected 1 place");
output = YAHOO.util.Number.format(123.123, {decimalPlaces:0});
Assert.areSame("123", output, "Incorrect decimal rounding: expected 0 places");
output = YAHOO.util.Number.format(123.123, {decimalPlaces:-1});
Assert.areSame("120", output, "Incorrect decimal rounding: expected -1 places");
output = YAHOO.util.Number.format("123123123", {thousandsSeparator:","});
Assert.areSame("123,123,123", output, "Incorrect thousands separation");
output = YAHOO.util.Number.format("123123123.176",{
prefix: "¥",
decimalPlaces:2,
thousandsSeparator:".",
decimalSeparator:","
});
Assert.areSame("¥123.123.123,18", output, "Incorrect Yen formatting");
}
};
var dataNumberTest = new DataUtilTestCase(dataNumberTemplate);
/**
*
*
* Runs tests.
*
*
*/
YAHOO.util.Event.addListener(window, "load", function() {
var logger = new TestLogger();
logger.hideCategory('info');
var datasourcesuite = new TestSuite("DataSource Test Suite");
datasourcesuite.add(datasourceTest);
datasourcesuite.add(dsCacheTest);
datasourcesuite.add(dsComplexArrayTest);
datasourcesuite.add(dsStaticMethodsTest);
datasourcesuite.add(dsXHRTest);
datasourcesuite.add(dsParseJSONTest);
datasourcesuite.add(dataNumberTest);
TestRunner.add(datasourcesuite);
YAHOO.util.Event.addListener("btnRun", "click", function(){TestRunner.run();});
YAHOO.util.Dom.get("btnRun").disabled = false;
if (parent && parent != window) {
YAHOO.tool.TestManager.load();
}
});
})();
</script>
</body>
</html>