ops.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. } from "../../../src/node/index";
  28. import TestRegister from "../../TestRegister";
  29. TestRegister.addApiTests([
  30. it("ADD: toggleString argument", () => {
  31. const result = ADD("sample input", {
  32. key: {
  33. string: "some key",
  34. option: "Hex"
  35. }
  36. });
  37. assert.equal(result.toString(), "aO[^ZS\u000eW\\^cb");
  38. }),
  39. it("addLineNumbers: No arguments", () => {
  40. const result = addLineNumbers("sample input");
  41. assert.equal(result.toString(), "1 sample input");
  42. }),
  43. it("adler32Checksum: No args", () => {
  44. const result = adler32Checksum("sample input");
  45. assert.equal(result.toString(), "1f2304d3");
  46. }),
  47. it("AES decrypt: toggleString and option", () => {
  48. const result = AESDecrypt("812c34ae6af353244a63c6ce23b7c34286b60be28ea4645523d4494700e7", {
  49. key: {
  50. string: "some longer key1",
  51. option: "utf8",
  52. },
  53. iv: {
  54. string: "some iv",
  55. option: "utf8",
  56. },
  57. mode: "OFB",
  58. });
  59. assert.equal(result.toString(), "a slightly longer sampleinput?");
  60. }),
  61. it("AffineCipherDecode: number input", () => {
  62. const result = affineCipherDecode("some input", {
  63. a: 7,
  64. b: 4
  65. });
  66. assert.strictEqual(result.toString(), "cuqa ifjgr");
  67. }),
  68. it("affineCipherEncode: number input", () => {
  69. const result = affineCipherEncode("some input", {
  70. a: 11,
  71. b: 6
  72. });
  73. assert.strictEqual(result.toString(), "weiy qtpsh");
  74. }),
  75. it("bifid cipher encode: string option", () => {
  76. const result = bifidCipherEncode("some input", {
  77. keyword: "mykeyword",
  78. });
  79. assert.strictEqual(result.toString(), "nmhs zmsdo");
  80. }),
  81. it("bitShiftRight: number and option", () => {
  82. const result = bitShiftRight("some bits to shift", {
  83. type: "Arithmetic shift",
  84. amount: 1,
  85. });
  86. assert.strictEqual(result.toString(), "9762\u001014:9\u0010:7\u00109443:");
  87. }),
  88. it("cartesianProduct: binary string", () => {
  89. const result = cartesianProduct("1:2\\n\\n3:4", {
  90. itemDelimiter: ":",
  91. });
  92. assert.strictEqual(result.toString(), "(1,3):(1,4):(2,3):(2,4)");
  93. }),
  94. it("CSS minify: boolean", () => {
  95. const input = `header {
  96. // comment
  97. width: 100%;
  98. color: white;
  99. }`;
  100. const result = CSSMinify(input, {
  101. preserveComments: true,
  102. });
  103. assert.strictEqual(result.toString(), "header {// comment width: 100%;color: white;}");
  104. })
  105. ]);