From 3a55b34214d32209ab918c0a05694972c177011a Mon Sep 17 00:00:00 2001 From: es45411 <135977478+es45411@users.noreply.github.com> Date: Mon, 12 May 2025 13:09:59 +0000 Subject: [PATCH] Add tests for URLDecode and URLEncode --- tests/operations/index.mjs | 1 + tests/operations/tests/URLEncodeDecode.mjs | 92 ++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/operations/tests/URLEncodeDecode.mjs diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index ab1ceb8f..27151c3c 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -163,6 +163,7 @@ import "./tests/TranslateDateTimeFormat.mjs"; import "./tests/Typex.mjs"; import "./tests/UnescapeString.mjs"; import "./tests/Unicode.mjs"; +import "./tests/URLEncodeDecode.mjs"; import "./tests/RSA.mjs"; import "./tests/CBOREncode.mjs"; import "./tests/CBORDecode.mjs"; diff --git a/tests/operations/tests/URLEncodeDecode.mjs b/tests/operations/tests/URLEncodeDecode.mjs new file mode 100644 index 00000000..444f76d3 --- /dev/null +++ b/tests/operations/tests/URLEncodeDecode.mjs @@ -0,0 +1,92 @@ +/** + * URLEncode and URLDecode tests. + * + * @author es45411 [135977478+es45411@users.noreply.github.com] + * + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +import TestRegister from "../../lib/TestRegister.mjs"; + +TestRegister.addTests([ + // URL Decode + { + name: "URLDecode: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "URL Decode", + args: [], + }, + ], + }, + { + name: "URLDecode: spaces without special chars", + input: "Hello%20world%21", + expectedOutput: "Hello world!", + recipeConfig: [ + { + op: "URL Decode", + args: [], + }, + ], + }, + { + name: "URLDecode: spaces with special chars", + input: "Hello%20world!", + expectedOutput: "Hello world!", + recipeConfig: [ + { + op: "URL Decode", + args: [], + }, + ], + }, + { + name: "URLDecode: decode plus as space", + input: "Hello%20world!", + expectedOutput: "Hello world!", + recipeConfig: [ + { + op: "URL Decode", + args: [], + }, + ], + }, + // URL Encode + { + name: "URLEncode: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "URL Encode", + args: [], + }, + ], + }, + { + name: "URLEncode: spaces without special chars", + input: "Hello world!", + expectedOutput: "Hello%20world!", + recipeConfig: [ + { + op: "URL Encode", + args: [], + }, + ], + }, + { + name: "URLEncode: spaces with special chars", + input: "Hello world!", + expectedOutput: "Hello%20world%21", + recipeConfig: [ + { + op: "URL Encode", + args: [true], + }, + ], + }, +]);