FlowControl.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. TestRegister.addTests([
  10. {
  11. name: "Fork: nothing",
  12. input: "",
  13. expectedOutput: "",
  14. recipeConfig: [
  15. {
  16. op: "Fork",
  17. args: ["\n", "\n", false],
  18. },
  19. ],
  20. },
  21. {
  22. name: "Fork, Merge: nothing",
  23. input: "",
  24. expectedOutput: "",
  25. recipeConfig: [
  26. {
  27. op: "Fork",
  28. args: ["\n", "\n", false],
  29. },
  30. {
  31. op: "Merge",
  32. args: [],
  33. },
  34. ],
  35. },
  36. {
  37. name: "Fork, (expect) Error, Merge",
  38. input: "1\n2\na\n4",
  39. expectedError: true,
  40. recipeConfig: [
  41. {
  42. op: "Fork",
  43. args: ["\n", "\n", false],
  44. },
  45. {
  46. op: "To Base",
  47. args: [16],
  48. },
  49. {
  50. op: "Merge",
  51. args: [],
  52. },
  53. ],
  54. },
  55. {
  56. name: "Fork, Conditional Jump, Encodings",
  57. input: "Some data with a 1 in it\nSome data with a 2 in it",
  58. 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",
  59. recipeConfig: [
  60. {"op":"Fork", "args":["\\n", "\\n", false]},
  61. {"op":"Conditional Jump", "args":["1", "2", "10"]},
  62. {"op":"To Hex", "args":["Space"]},
  63. {"op":"Return", "args":[]},
  64. {"op":"To Base64", "args":["A-Za-z0-9+/="]}
  65. ]
  66. },
  67. {
  68. name: "Conditional Jump: Skips 0",
  69. input: [
  70. "match",
  71. "should be changed 1",
  72. "should be changed 2",
  73. ].join("\n"),
  74. expectedOutput: [
  75. "match",
  76. "should be changed 1 was changed",
  77. "should be changed 2 was changed"
  78. ].join("\n"),
  79. recipeConfig: [
  80. {
  81. op: "Conditional Jump",
  82. args: ["match", 0, 0],
  83. },
  84. {
  85. op: "Find / Replace",
  86. args: [
  87. {
  88. "option": "Regex",
  89. "string": "should be changed 1"
  90. },
  91. "should be changed 1 was changed",
  92. true,
  93. true,
  94. true,
  95. ],
  96. },
  97. {
  98. op: "Find / Replace",
  99. args: [
  100. {
  101. "option": "Regex",
  102. "string": "should be changed 2"
  103. },
  104. "should be changed 2 was changed",
  105. true,
  106. true,
  107. true,
  108. ],
  109. },
  110. ],
  111. },
  112. ]);