ops.mjs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* eslint no-console: 0 */
  2. /**
  3. * nodeApi.js
  4. *
  5. * Test node api operations
  6. *
  7. * Aim of these tests is to ensure each arg type is
  8. * handled correctly by the wrapper.
  9. *
  10. * @author d98762625 [d98762625@gmail.com]
  11. * @copyright Crown Copyright 2018
  12. * @license Apache-2.0
  13. */
  14. import assert from "assert";
  15. import it from "../assertionHandler";
  16. import {
  17. ADD,
  18. addLineNumbers,
  19. adler32Checksum,
  20. AESDecrypt,
  21. affineCipherDecode,
  22. affineCipherEncode,
  23. bifidCipherEncode,
  24. bitShiftRight,
  25. cartesianProduct,
  26. CSSMinify,
  27. toBase64,
  28. } from "../../../src/node/index";
  29. import TestRegister from "../../TestRegister";
  30. TestRegister.addApiTests([
  31. it("ADD: toggleString argument", () => {
  32. const result = ADD("sample input", {
  33. key: {
  34. string: "some key",
  35. option: "Hex"
  36. }
  37. });
  38. assert.equal(result.toString(), "aO[^ZS\u000eW\\^cb");
  39. }),
  40. it("addLineNumbers: No arguments", () => {
  41. const result = addLineNumbers("sample input");
  42. assert.equal(result.toString(), "1 sample input");
  43. }),
  44. it("adler32Checksum: No args", () => {
  45. const result = adler32Checksum("sample input");
  46. assert.equal(result.toString(), "1f2304d3");
  47. }),
  48. it("AES decrypt: toggleString and option", () => {
  49. const result = AESDecrypt("812c34ae6af353244a63c6ce23b7c34286b60be28ea4645523d4494700e7", {
  50. key: {
  51. string: "some longer key1",
  52. option: "utf8",
  53. },
  54. iv: {
  55. string: "some iv",
  56. option: "utf8",
  57. },
  58. mode: "OFB",
  59. });
  60. assert.equal(result.toString(), "a slightly longer sampleinput?");
  61. }),
  62. it("AffineCipherDecode: number input", () => {
  63. const result = affineCipherDecode("some input", {
  64. a: 7,
  65. b: 4
  66. });
  67. assert.strictEqual(result.toString(), "cuqa ifjgr");
  68. }),
  69. it("affineCipherEncode: number input", () => {
  70. const result = affineCipherEncode("some input", {
  71. a: 11,
  72. b: 6
  73. });
  74. assert.strictEqual(result.toString(), "weiy qtpsh");
  75. }),
  76. it("bifid cipher encode: string option", () => {
  77. const result = bifidCipherEncode("some input", {
  78. keyword: "mykeyword",
  79. });
  80. assert.strictEqual(result.toString(), "nmhs zmsdo");
  81. }),
  82. it("bitShiftRight: number and option", () => {
  83. const result = bitShiftRight("some bits to shift", {
  84. type: "Arithmetic shift",
  85. amount: 1,
  86. });
  87. assert.strictEqual(result.toString(), "9762\u001014:9\u0010:7\u00109443:");
  88. }),
  89. it("cartesianProduct: binary string", () => {
  90. const result = cartesianProduct("1:2\\n\\n3:4", {
  91. itemDelimiter: ":",
  92. });
  93. assert.strictEqual(result.toString(), "(1,3):(1,4):(2,3):(2,4)");
  94. }),
  95. it("CSS minify: boolean", () => {
  96. const input = `header {
  97. // comment
  98. width: 100%;
  99. color: white;
  100. }`;
  101. const result = CSSMinify(input, {
  102. preserveComments: true,
  103. });
  104. assert.strictEqual(result.toString(), "header {// comment width: 100%;color: white;}");
  105. }),
  106. it("toBase64: editableOption", () => {
  107. const result = toBase64("some input", {
  108. alphabet: {
  109. value: "0-9A-W"
  110. },
  111. });
  112. assert.strictEqual(result.toString(), "SPI1R1T0");
  113. }),
  114. it("toBase64: editableOptions key is value", () => {
  115. const result = toBase64("some input", {
  116. alphabet: "0-9A-W",
  117. });
  118. assert.strictEqual(result.toString(), "SPI1R1T0");
  119. })
  120. ]);