| 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 |
</script> |
|---|
| 38 |
</head> |
|---|
| 39 |
<body> |
|---|
| 40 |
</body> |
|---|
| 41 |
</html> |
|---|