FlowControl.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * Flow Control tests.
  3. *
  4. * @author tlwr [toby@toby.codes]
  5. *
  6. * @copyright Crown Copyright 2017
  7. * @license Apache-2.0
  8. */
  9. import TestRegister from "../../TestRegister.js";
  10. TestRegister.addTests([
  11. {
  12. name: "Fork: nothing",
  13. input: "",
  14. expectedOutput: "",
  15. recipeConfig: [
  16. {
  17. op: "Fork",
  18. args: ["\n", "\n", false],
  19. },
  20. ],
  21. },
  22. {
  23. name: "Fork, Merge: nothing",
  24. input: "",
  25. expectedOutput: "",
  26. recipeConfig: [
  27. {
  28. op: "Fork",
  29. args: ["\n", "\n", false],
  30. },
  31. {
  32. op: "Merge",
  33. args: [],
  34. },
  35. ],
  36. },
  37. {
  38. name: "Fork, (expect) Error, Merge",
  39. input: "1\n2\na\n4",
  40. expectedError: true,
  41. recipeConfig: [
  42. {
  43. op: "Fork",
  44. args: ["\n", "\n", false],
  45. },
  46. {
  47. op: "To Base",
  48. args: [16],
  49. },
  50. {
  51. op: "Merge",
  52. args: [],
  53. },
  54. ],
  55. },
  56. {
  57. name: "Fork, Conditional Jump, Encodings",
  58. input: "Some data with a 1 in it\nSome data with a 2 in it",
  59. expectedOutput: "U29tZSBkYXRhIHdpdGggYSAxIGluIGl0\n53 6f 6d 65 20 64 61 74 61 20 77 69 74 68 20 61 20 32 20 69 6e 20 69 74\n",
  60. recipeConfig: [
  61. {"op":"Fork", "args":["\\n", "\\n", false]},
  62. {"op":"Conditional Jump", "args":["1", "2", "10"]},
  63. {"op":"To Hex", "args":["Space"]},
  64. {"op":"Return", "args":[]},
  65. {"op":"To Base64", "args":["A-Za-z0-9+/="]}
  66. ]
  67. },
  68. {
  69. name: "Conditional Jump: Skips 0",
  70. input: [
  71. "match",
  72. "should be changed 1",
  73. "should be changed 2",
  74. ].join("\n"),
  75. expectedOutput: [
  76. "match",
  77. "should be changed 1 was changed",
  78. "should be changed 2 was changed"
  79. ].join("\n"),
  80. recipeConfig: [
  81. {
  82. op: "Conditional Jump",
  83. args: ["match", 0, 0],
  84. },
  85. {
  86. op: "Find / Replace",
  87. args: [
  88. {
  89. "option": "Regex",
  90. "string": "should be changed 1"
  91. },
  92. "should be changed 1 was changed",
  93. true,
  94. true,
  95. true,
  96. ],
  97. },
  98. {
  99. op: "Find / Replace",
  100. args: [
  101. {
  102. "option": "Regex",
  103. "string": "should be changed 2"
  104. },
  105. "should be changed 2 was changed",
  106. true,
  107. true,
  108. true,
  109. ],
  110. },
  111. ],
  112. },
  113. {
  114. name: "Comment: nothing",
  115. input: "",
  116. expectedOutput: "",
  117. recipeConfig: [
  118. {
  119. "op": "Comment",
  120. "args": [""]
  121. }
  122. ]
  123. },
  124. {
  125. name: "Fork, Comment, Base64",
  126. input: "cat\nsat\nmat",
  127. expectedOutput: "Y2F0\nc2F0\nbWF0\n",
  128. recipeConfig: [
  129. {
  130. "op": "Fork",
  131. "args": ["\\n","\\n",false]
  132. },
  133. {
  134. "op": "Comment",
  135. "args": ["Testing 123"]
  136. },
  137. {
  138. "op": "To Base64",
  139. "args": ["A-Za-z0-9+/="]
  140. }
  141. ]
  142. },
  143. ]);