serialize.js 1.2 KB

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