Kirill 179eb9a379
Validate Wrap line width (#2606)
Co-authored-by: GCHQDeveloper581 <63102987+GCHQDeveloper581@users.noreply.github.com>
Co-authored-by: C85297 <95289555+C85297@users.noreply.github.com>
2026-07-03 11:06:55 +01:00

89 lines
2.5 KiB
JavaScript

/**
* @author 0xff1ce [github.com/0xff1ce]
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
// Add tests specific to the Wrap operation
{
name: "Wrap text at 64 characters",
input: "A".repeat(128), // Generate an input string of 128 'A' characters
expectedOutput: "A".repeat(64) + "\n" + "A".repeat(64), // Expected output with a line break after 64 characters
recipeConfig: [
{
"op": "Wrap",
"args": [64]
},
],
},
{
name: "Wrap text at 32 characters",
input: "B".repeat(96), // Generate an input string of 96 'B' characters
expectedOutput: "B".repeat(32) + "\n" + "B".repeat(32) + "\n" + "B".repeat(32), // Expected output with line breaks after every 32 characters
recipeConfig: [
{
"op": "Wrap",
"args": [32]
},
],
},
{
name: "Wrap text at 10 characters",
input: "1234567890".repeat(10), // Generate an input string by repeating '1234567890'
expectedOutput: Array(10).fill("1234567890").join("\n"), // Expected output with line breaks every 10 characters
recipeConfig: [
{
"op": "Wrap",
"args": [10]
},
],
},
{
name: "Wrap rejects zero line width",
input: "hello",
expectedOutput: "Line Width must be greater than or equal to 1.",
recipeConfig: [
{
"op": "Wrap",
"args": [0]
},
],
},
{
name: "Wrap rejects negative line width",
input: "hello",
expectedOutput: "Line Width must be greater than or equal to 1.",
recipeConfig: [
{
"op": "Wrap",
"args": [-1]
},
],
},
{
name: "Wrap rejects non-integer line width",
input: "hello",
expectedOutput: "Line Width must be an integer.",
recipeConfig: [
{
"op": "Wrap",
"args": [1.1]
},
],
},
{
name: "Wrap rejects excessive line width",
input: "hello",
expectedOutput: "Line Width must be less than or equal to 65536.",
recipeConfig: [
{
"op": "Wrap",
"args": [65537]
},
],
}
]);