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
|
<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>
|