80572b77fc7eb962c3856a62afaa6cb233c25f7b.svn-base 1.3 KB

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