diff options
Diffstat (limited to 'misc/openlayers/tests/Format/JSON.html')
-rw-r--r-- | misc/openlayers/tests/Format/JSON.html | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/misc/openlayers/tests/Format/JSON.html b/misc/openlayers/tests/Format/JSON.html new file mode 100644 index 0000000..84461e1 --- /dev/null +++ b/misc/openlayers/tests/Format/JSON.html @@ -0,0 +1,53 @@ +<html> +<head> + <script src="../OLLoader.js"></script> + <script type="text/javascript"> + + function test_Format_JSON_constructor(t) { + t.plan(4); + + var options = {'foo': 'bar'}; + var format = new OpenLayers.Format.JSON(options); + t.ok(format instanceof OpenLayers.Format.JSON, + "new OpenLayers.Format.JSON returns object" ); + t.eq(format.foo, "bar", "constructor sets options correctly"); + t.eq(typeof format.read, "function", "format has a read function"); + t.eq(typeof format.write, "function", "format has a write function"); + } + + function test_Format_JSON_parser(t) { + t.plan(2); + + var format = new OpenLayers.Format.JSON(); + var data = format.read('{"a":["b"], "c":1}'); + var obj = {"a":["b"], "c":1}; + t.eq(obj['a'], data['a'], "element with array parsed correctly."); + t.eq(obj['c'], data['c'], "element with number parsed correctly."); + } + + function test_Format_JSON_writer(t) { + t.plan(1); + + var format = new OpenLayers.Format.JSON(); + var data = format.write({"a":["b"], "c":1}); + var obj = '{"a":["b"],"c":1}'; + t.eq(data, obj, "writing data to json works."); + } + + + function test_keepData(t) { + t.plan(2); + + var options = {'keepData': true}; + var format = new OpenLayers.Format.JSON(options); + format.read('{"a":["b"], "c":1}'); + + t.ok(format.data != null, 'data property is not null after read with keepData=true'); + t.eq(format.data.c,1,'keepData keeps the right data'); + } + + </script> +</head> +<body> +</body> +</html> |