]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Format/JSON.html
initial commit
[syp.git] / openlayers / tests / Format / JSON.html
1 <html> 
2 <head> 
3     <script src="../../lib/OpenLayers.js"></script> 
4     <script type="text/javascript">
5
6     function test_Format_JSON_constructor(t) { 
7         t.plan(4); 
8          
9         var options = {'foo': 'bar'}; 
10         var format = new OpenLayers.Format.JSON(options); 
11         t.ok(format instanceof OpenLayers.Format.JSON, 
12              "new OpenLayers.Format.JSON returns object" ); 
13         t.eq(format.foo, "bar", "constructor sets options correctly"); 
14         t.eq(typeof format.read, "function", "format has a read function"); 
15         t.eq(typeof format.write, "function", "format has a write function"); 
16     }
17
18     function test_Format_JSON_parser(t) { 
19         t.plan(2); 
20          
21         var format = new OpenLayers.Format.JSON(); 
22         var data = format.read('{"a":["b"], "c":1}');
23         var obj = {"a":["b"], "c":1};
24         t.eq(obj['a'], data['a'], "element with array parsed correctly.");  
25         t.eq(obj['c'], data['c'], "element with number parsed correctly.");  
26     }
27
28     function test_Format_JSON_writer(t) { 
29         t.plan(1); 
30          
31         var format = new OpenLayers.Format.JSON(); 
32         var data = format.write({"a":["b"], "c":1});
33         var obj = '{"a":["b"],"c":1}';
34         t.eq(data, obj, "writing data to json works.");
35     }
36
37
38     function test_keepData(t) { 
39         t.plan(2);
40
41         var options = {'keepData': true};
42         var format = new OpenLayers.Format.JSON(options); 
43         format.read('{"a":["b"], "c":1}');
44
45         t.ok(format.data != null, 'data property is not null after read with keepData=true');
46         t.eq(format.data.c,1,'keepData keeps the right data');
47     }
48
49     </script> 
50 </head> 
51 <body> 
52 </body> 
53 </html>