diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index 6d5b266f..f198e440 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -162,6 +162,7 @@ import "./tests/SymmetricDifference.mjs"; import "./tests/TakeNthBytes.mjs"; import "./tests/Template.mjs"; import "./tests/TextEncodingBruteForce.mjs"; +import "./tests/TextIntegerConverter.mjs"; import "./tests/ToFromInsensitiveRegex.mjs"; import "./tests/TranslateDateTimeFormat.mjs"; import "./tests/Typex.mjs"; diff --git a/tests/operations/tests/TextIntegerConverter.mjs b/tests/operations/tests/TextIntegerConverter.mjs new file mode 100644 index 00000000..17466564 --- /dev/null +++ b/tests/operations/tests/TextIntegerConverter.mjs @@ -0,0 +1,163 @@ +/** + * Text-Integer Conversion tests. + * + * @author p-leriche [philip.leriche@cantab.net] + * + * @copyright Crown Copyright 2025 + * @license Apache-2.0 + */ +import TestRegister from "../../lib/TestRegister.mjs"; + +TestRegister.addTests([ + { + name: "Text-Integer Conversion quoted string to decimal", + input: "\"ABC\"", + expectedOutput: "4276803", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Decimal"], + }, + ], + }, + { + name: "Text-Integer Conversion quoted string to hexadecimal", + input: "\"ABC\"", + expectedOutput: "0x414243", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Hexadecimal"], + }, + ], + }, + { + name: "Text-Integer Conversion single quoted string to decimal", + input: "'Hello'", + expectedOutput: "310939249775", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Decimal"], + }, + ], + }, + { + name: "Text-Integer Conversion decimal to string", + input: "4276803", + expectedOutput: "ABC", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["String"], + }, + ], + }, + { + name: "Text-Integer Conversion hexadecimal to string", + input: "0x48656C6C6F", + expectedOutput: "Hello", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["String"], + }, + ], + }, + { + name: "Text-Integer Conversion round-trip string.decimal.string", + input: "\"Test\"", + expectedOutput: "Test", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Decimal"], + }, + { + op: "Text-Integer Conversion", + args: ["String"], + }, + ], + }, + { + name: "Text-Integer Conversion round-trip string.hex.string", + input: "\"CyberChef\"", + expectedOutput: "CyberChef", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Hexadecimal"], + }, + { + op: "Text-Integer Conversion", + args: ["String"], + }, + ], + }, + { + name: "Text-Integer Conversion unquoted text to decimal", + input: "Hi", + expectedOutput: "18537", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Decimal"], + }, + ], + }, + { + name: "Text-Integer Conversion single character", + input: "\"A\"", + expectedOutput: "65", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Decimal"], + }, + ], + }, + { + name: "Text-Integer Conversion hex to decimal conversion", + input: "0xFF", + expectedOutput: "255", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Decimal"], + }, + ], + }, + { + name: "Text-Integer Conversion decimal to hex conversion", + input: "255", + expectedOutput: "0xff", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Hexadecimal"], + }, + ], + }, + { + name: "Text-Integer Conversion large number to string", + input: "113091951015816448506195587157728348242683688608116", + expectedOutput: "Mary had a little cat", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["String"], + }, + ], + }, + { + name: "Text-Integer Conversion whitespace handling (quoted)", + input: "\" test \"", + expectedOutput: "2314978187545944096", + recipeConfig: [ + { + op: "Text-Integer Conversion", + args: ["Decimal"], + }, + ], + }, +]);