Adding operation to insert a delimiter at a given interval

This commit is contained in:
Niall 2024-08-23 21:09:42 +00:00
parent d635cca210
commit 5cf7f823e6
4 changed files with 122 additions and 1 deletions

View file

@ -83,6 +83,7 @@ import "./tests/Hexdump.mjs";
import "./tests/HKDF.mjs";
import "./tests/Image.mjs";
import "./tests/IndexOfCoincidence.mjs";
import "./tests/InsertDelimiter.mjs";
import "./tests/JA3Fingerprint.mjs";
import "./tests/JA4.mjs";
import "./tests/JA3SFingerprint.mjs";

View file

@ -0,0 +1,65 @@
/**
* @author 0xff1ce [github.com/0xff1ce]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Insert space every 8 characters",
input: "010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001",
expectedOutput: "01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100 00100001",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [8, " "]
},
],
},
{
name: "Insert newline every 4 characters",
input: "ABCDEFGHIJKL",
expectedOutput: "ABCD\nEFGH\nIJKL",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [4, "\n"]
},
],
},
{
name: "Insert hyphen every 3 characters",
input: "1234567890",
expectedOutput: "123-456-789-0",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [3, "-"]
},
],
},
{
name: "Use a float as delimiter",
input: "1234567890",
expectedOutput: "123-456-789-0",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [3.4, "-"]
},
],
},
{
name: "Handle empty input gracefully",
input: "",
expectedOutput: "",
recipeConfig: [
{
"op": "Insert Delimiter",
"args": [8, " "]
},
],
}
]);