serialize.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. module.exports = function (t, a) {
  3. var fn = function (raz, dwa) {
  4. return raz + dwa;
  5. };
  6. a(t(), "undefined", "Undefined");
  7. a(t(null), "null", "Null");
  8. a(t(null), "null", "Null");
  9. a(t("raz"), "\"raz\"", "String");
  10. a(t("raz\"ddwa\ntrzy"), "\"raz\\\"ddwa\\ntrzy\"", "String with escape");
  11. a(t(false), "false", "Booelean");
  12. a(t(fn), String(fn), "Function");
  13. a(t(/raz-dwa/g), "/raz-dwa/g", "RegExp");
  14. a(t(new Date(1234567)), "new Date(1234567)", "Date");
  15. a(t([]), "[]", "Empty array");
  16. a(
  17. t([undefined, false, null, "raz\"ddwa\ntrzy", fn, /raz/g, new Date(1234567), ["foo"]]),
  18. "[undefined,false,null,\"raz\\\"ddwa\\ntrzy\"," +
  19. String(fn) +
  20. ",/raz/g,new Date(1234567),[\"foo\"]]",
  21. "Rich Array"
  22. );
  23. a(t({}), "{}", "Empty object");
  24. a(
  25. t({
  26. raz: undefined,
  27. dwa: false,
  28. trzy: null,
  29. cztery: "raz\"ddwa\ntrzy",
  30. piec: fn,
  31. szesc: /raz/g,
  32. siedem: new Date(1234567),
  33. osiem: ["foo", 32],
  34. dziewiec: { foo: "bar", dwa: 343 }
  35. }),
  36. "{\"raz\":undefined,\"dwa\":false,\"trzy\":null,\"cztery\":\"raz\\\"ddwa\\ntrzy\"," +
  37. "\"piec\":" +
  38. String(fn) +
  39. ",\"szesc\":/raz/g,\"siedem\":new Date(1234567),\"osiem\":[\"foo\",32]," +
  40. "\"dziewiec\":{\"foo\":\"bar\",\"dwa\":343}}",
  41. "Rich object"
  42. );
  43. };