Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["tests._base.json"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["tests._base.json"] = true;
3
dojo.provide("tests._base.json");
4
 
5
tests.register("tests._base.json",
6
	[
7
		//Not testing dojo.toJson() on its own since Rhino will output the object properties in a different order.
8
		//Still valid json, but just in a different order than the source string.
9
 
10
		// take a json-compatible object, convert it to a json string, then put it back into json.
11
		function toAndFromJson(t){
12
			var testObj = {a:"a", b:1, c:"c", d:"d", e:{e1:"e1", e2:2}, f:[1,2,3], g:"g",h:{h1:{h2:{h3:"h3"}}}};
13
 
14
			var mirrorObj = dojo.fromJson(dojo.toJson(testObj));
15
			t.assertEqual("a", mirrorObj.a);
16
			t.assertEqual(1, mirrorObj.b);
17
			t.assertEqual("c", mirrorObj.c);
18
			t.assertEqual("d", mirrorObj.d);
19
			t.assertEqual("e1", mirrorObj.e.e1);
20
			t.assertEqual(2, mirrorObj.e.e2);
21
			t.assertEqual(1, mirrorObj.f[0]);
22
			t.assertEqual(2, mirrorObj.f[1]);
23
			t.assertEqual(3, mirrorObj.f[2]);
24
			t.assertEqual("g", mirrorObj.g);
25
			t.assertEqual("h3", mirrorObj.h.h1.h2.h3);
26
		}
27
	]
28
);
29
 
30
 
31
}