3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_Format_JSON_constructor(t) {
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");
18 function test_Format_JSON_parser(t) {
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.");
28 function test_Format_JSON_writer(t) {
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.");
38 function test_keepData(t) {
41 var options = {'keepData': true};
42 var format = new OpenLayers.Format.JSON(options);
43 format.read('{"a":["b"], "c":1}');
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');