JSONBeautify.mjs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * JSONBeautify tests.
  3. *
  4. * @author Phillip Nordwall [Phillip.Nordwall@gmail.com]
  5. *
  6. * @copyright Crown Copyright 2018
  7. * @license Apache-2.0
  8. */
  9. import TestRegister from "../../TestRegister";
  10. TestRegister.addTests([
  11. {
  12. name: "JSON Beautify: space, ''",
  13. input: "",
  14. expectedOutput: "",
  15. recipeConfig: [
  16. {
  17. op: "JSON Beautify",
  18. args: [" ", false],
  19. },
  20. ],
  21. },
  22. {
  23. name: "JSON Beautify: space, number",
  24. input: "42",
  25. expectedOutput: "42",
  26. recipeConfig: [
  27. {
  28. op: "JSON Beautify",
  29. args: [" ", false],
  30. },
  31. ],
  32. },
  33. {
  34. name: "JSON Beautify: space, string",
  35. input: "\"string\"",
  36. expectedOutput: "\"string\"",
  37. recipeConfig: [
  38. {
  39. op: "JSON Beautify",
  40. args: [" ", false],
  41. },
  42. ],
  43. },
  44. {
  45. name: "JSON Beautify: space, boolean",
  46. input: "false",
  47. expectedOutput: "false",
  48. recipeConfig: [
  49. {
  50. op: "JSON Beautify",
  51. args: [" ", false],
  52. },
  53. ],
  54. },
  55. {
  56. name: "JSON Beautify: space, emptyList",
  57. input: "[]",
  58. expectedOutput: "[]",
  59. recipeConfig: [
  60. {
  61. op: "JSON Beautify",
  62. args: [" ", false],
  63. },
  64. ],
  65. },
  66. {
  67. name: "JSON Beautify: space, list",
  68. input: "[2,1]",
  69. expectedOutput: "[\n 2,\n 1\n]",
  70. recipeConfig: [
  71. {
  72. op: "JSON Beautify",
  73. args: [" ", false],
  74. },
  75. ],
  76. },
  77. {
  78. name: "JSON Beautify: tab, list",
  79. input: "[2,1]",
  80. expectedOutput: "[\n\t2,\n\t1\n]",
  81. recipeConfig: [
  82. {
  83. op: "JSON Beautify",
  84. args: ["\t", false],
  85. },
  86. ],
  87. },
  88. {
  89. name: "JSON Beautify: space, object",
  90. input: "{\"second\":2,\"first\":3}",
  91. expectedOutput: "{\n \"second\": 2,\n \"first\": 3\n}",
  92. recipeConfig: [
  93. {
  94. op: "JSON Beautify",
  95. args: [" ", false],
  96. },
  97. ],
  98. },
  99. {
  100. name: "JSON Beautify: tab, nested",
  101. input: "[2,{\"second\":2,\"first\":3,\"beginning\":{\"j\":\"3\",\"i\":[2,3,false]}},1,2,3]",
  102. expectedOutput: "[\n\t2,\n\t{\n\t\t\"second\": 2,\n\t\t\"first\": 3,\n\t\t\"beginning\": {\n\t\t\t\"j\": \"3\",\n\t\t\t\"i\": [\n\t\t\t\t2,\n\t\t\t\t3,\n\t\t\t\tfalse\n\t\t\t]\n\t\t}\n\t},\n\t1,\n\t2,\n\t3\n]",
  103. recipeConfig: [
  104. {
  105. op: "JSON Beautify",
  106. args: ["\t", false],
  107. },
  108. ],
  109. },
  110. {
  111. name: "JSON Beautify: tab, nested, sorted",
  112. input: "[2,{\"second\":2,\"first\":3,\"beginning\":{\"j\":\"3\",\"i\":[2,3,false]}},1,2,3]",
  113. expectedOutput: "[\n\t2,\n\t{\n\t\t\"beginning\": {\n\t\t\t\"i\": [\n\t\t\t\t2,\n\t\t\t\t3,\n\t\t\t\tfalse\n\t\t\t],\n\t\t\t\"j\": \"3\"\n\t\t},\n\t\t\"first\": 3,\n\t\t\"second\": 2\n\t},\n\t1,\n\t2,\n\t3\n]",
  114. recipeConfig: [
  115. {
  116. op: "JSON Beautify",
  117. args: ["\t", true],
  118. },
  119. ],
  120. },
  121. ]);