fix: rely on wrap argument metadata validation
This commit is contained in:
parent
e1da48cbc9
commit
28d5a1023d
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import OperationError from "../errors/OperationError.mjs";
|
|
||||||
|
|
||||||
const MAX_LINE_WIDTH = 65536;
|
const MAX_LINE_WIDTH = 65536;
|
||||||
|
|
||||||
@ -45,16 +44,6 @@ class Wrap extends Operation {
|
|||||||
run(input, args) {
|
run(input, args) {
|
||||||
if (!input) return ""; // Handle empty input
|
if (!input) return ""; // Handle empty input
|
||||||
const lineWidth = args[0];
|
const lineWidth = args[0];
|
||||||
|
|
||||||
if (!Number.isInteger(lineWidth))
|
|
||||||
throw new OperationError("Line Width must be an integer.");
|
|
||||||
|
|
||||||
if (lineWidth < 1)
|
|
||||||
throw new OperationError("Line Width must be greater than or equal to 1.");
|
|
||||||
|
|
||||||
if (lineWidth > MAX_LINE_WIDTH)
|
|
||||||
throw new OperationError(`Line Width must be less than or equal to ${MAX_LINE_WIDTH}.`);
|
|
||||||
|
|
||||||
const regex = new RegExp(`.{1,${lineWidth}}`, "g");
|
const regex = new RegExp(`.{1,${lineWidth}}`, "g");
|
||||||
return input.match(regex).join("\n");
|
return input.match(regex).join("\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,38 +40,5 @@ TestRegister.addTests([
|
|||||||
"args": [10]
|
"args": [10]
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Wrap rejects negative line width",
|
|
||||||
input: "hi, how about you",
|
|
||||||
expectedOutput: "Line Width must be greater than or equal to 1.",
|
|
||||||
recipeConfig: [
|
|
||||||
{
|
|
||||||
"op": "Wrap",
|
|
||||||
"args": [-1]
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Wrap rejects floating-point line width",
|
|
||||||
input: "hi, how about you",
|
|
||||||
expectedOutput: "Line Width must be an integer.",
|
|
||||||
recipeConfig: [
|
|
||||||
{
|
|
||||||
"op": "Wrap",
|
|
||||||
"args": [1.1]
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Wrap rejects excessively large line width",
|
|
||||||
input: "hi, how about you",
|
|
||||||
expectedOutput: "Line Width must be less than or equal to 65536.",
|
|
||||||
recipeConfig: [
|
|
||||||
{
|
|
||||||
"op": "Wrap",
|
|
||||||
"args": [1.1761717177171882e+23]
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user