From db0e08518a7d37b37a31ae6904e2a1d379e4545f Mon Sep 17 00:00:00 2001 From: Jyeu Date: Sat, 14 Mar 2026 22:31:35 +0800 Subject: [PATCH] test(operations): add tests for `ToFullwidth` function --- tests/operations/index.mjs | 1 + tests/operations/tests/ToFullwidth.mjs | 144 +++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 tests/operations/tests/ToFullwidth.mjs diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index fb03a5f71..bd08a7c7e 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -167,6 +167,7 @@ import "./tests/TakeNthBytes.mjs"; import "./tests/Template.mjs"; import "./tests/TextEncodingBruteForce.mjs"; import "./tests/TextIntegerConverter.mjs"; +import "./tests/ToFullwidth.mjs"; import "./tests/ToFromInsensitiveRegex.mjs"; import "./tests/TranslateDateTimeFormat.mjs"; import "./tests/Typex.mjs"; diff --git a/tests/operations/tests/ToFullwidth.mjs b/tests/operations/tests/ToFullwidth.mjs new file mode 100644 index 000000000..0d1c52fd9 --- /dev/null +++ b/tests/operations/tests/ToFullwidth.mjs @@ -0,0 +1,144 @@ +/** + * To Fullwidth tests. + * + * @author jyeu [chen@jyeu.xyz] + * + * @copyright Crown Copyright 2026 + * @license Apache-2.0 + */ +import TestRegister from "../../lib/TestRegister.mjs"; + +TestRegister.addTests([ + { + name: "To Fullwidth: empty string", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: lowercase letters", + input: "admin", + expectedOutput: "\uFF41\uFF44\uFF4D\uFF49\uFF4E", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: uppercase letters", + input: "ADMIN", + expectedOutput: "\uFF21\uFF24\uFF2D\uFF29\uFF2E", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: digits", + input: "0123456789", + expectedOutput: "\uFF10\uFF11\uFF12\uFF13\uFF14\uFF15\uFF16\uFF17\uFF18\uFF19", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: space becomes ideographic space (U+3000)", + input: "hello world", + expectedOutput: "\uFF48\uFF45\uFF4C\uFF4C\uFF4F\u3000\uFF57\uFF4F\uFF52\uFF4C\uFF44", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: common punctuation and symbols", + input: "!@#$%^&*()_+-=[]{}|;':\",./<>?", + expectedOutput: "\uFF01\uFF20\uFF03\uFF04\uFF05\uFF3E\uFF06\uFF0A\uFF08\uFF09\uFF3F\uFF0B\uFF0D\uFF1D\uFF3B\uFF3D\uFF5B\uFF5D\uFF5C\uFF1B\uFF07\uFF1A\uFF02\uFF0C\uFF0E\uFF0F\uFF1C\uFF1E\uFF1F", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: slash for WAF bypass simulation", + input: "/admin/secret", + expectedOutput: "\uFF0F\uFF41\uFF44\uFF4D\uFF49\uFF4E\uFF0F\uFF53\uFF45\uFF43\uFF52\uFF45\uFF54", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: non-ASCII characters pass through unchanged", + input: "你好世界", + expectedOutput: "你好世界", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: newline passes through unchanged", + input: "line1\nline2", + expectedOutput: "\uFF4C\uFF49\uFF4E\uFF45\uFF11\n\uFF4C\uFF49\uFF4E\uFF45\uFF12", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: mixed ASCII and non-ASCII", + input: "hello,世界!", + expectedOutput: "\uFF48\uFF45\uFF4C\uFF4C\uFF4F\uFF0C世界\uFF01", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: boundary character 0x21 (!)", + input: "!", + expectedOutput: "\uFF01", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, + { + name: "To Fullwidth: boundary character 0x7E (~)", + input: "~", + expectedOutput: "\uFF5E", + recipeConfig: [ + { + op: "To Fullwidth", + args: [], + }, + ], + }, +]);