1
0
mirror of synced 2024-11-15 18:53:22 +01:00
CyberChef/test/tests/operations/StrUtils.js
Matt C 6698a2ac13 Added tests + fixes for PR
- actually removed prev func
- shuffled some stuff around
2017-08-07 16:08:50 +01:00

280 lines
7.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* StrUtils tests.
*
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../../TestRegister.js";
TestRegister.addTests([
{
name: "Regex, non-HTML op",
input: "/<>",
expectedOutput: "/<>",
recipeConfig: [
{
"op": "Regular expression",
"args": ["User defined", "", true, true, false, "Highlight matches"]
},
{
"op": "Remove whitespace",
"args": [true, true, true, true, true, false]
}
],
},
{
name: "Diff, basic usage",
input: "testing23\n\ntesting123",
expectedOutput: "testing<span class='hl5'>1</span>23",
recipeConfig: [
{
"op": "Diff",
"args": ["\\n\\n", "Character", true, true, false]
}
],
},
{
name: "Head 0",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", 0]
}
],
},
{
name: "Head 1",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [1].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", 1]
}
],
},
{
name: "Head 2",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [1, 2].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", 2]
}
],
},
{
name: "Head 6",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", 6]
}
],
},
{
name: "Head big",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", 100]
}
],
},
{
name: "Head all but 1",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [1, 2, 3, 4, 5].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", -1]
}
],
},
{
name: "Head all but 2",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [1, 2, 3, 4].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", -2]
}
],
},
{
name: "Head all but 6",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", -6]
}
],
},
{
name: "Head all but big",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [].join("\n"),
recipeConfig: [
{
"op": "Head",
"args": ["Line feed", -100]
}
],
},
{
name: "Tail 0",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", 0]
}
],
},
{
name: "Tail 1",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [6].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", 1]
}
],
},
{
name: "Tail 2",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [5, 6].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", 2]
}
],
},
{
name: "Tail 6",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", 6]
}
],
},
{
name: "Tail big",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", 100]
}
],
},
{
name: "Tail all but 1",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [2, 3, 4, 5, 6].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", -1]
}
],
},
{
name: "Tail all but 2",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [3, 4, 5, 6].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", -2]
}
],
},
{
name: "Tail all but 6",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", -6]
}
],
},
{
name: "Tail all but big",
input: [1, 2, 3, 4, 5, 6].join("\n"),
expectedOutput: [].join("\n"),
recipeConfig: [
{
"op": "Tail",
"args": ["Line feed", -100]
}
],
},
{
name: "Escape String: quotes",
input: "Hello \"World\"! Escape 'these' quotes.",
expectedOutput: "Hello \\\"World\\\"! Escape \\'these\\' quotes.",
recipeConfig: [
{
"op": "Escape String",
"args": []
}
],
},
{
name: "Escape String: special characters",
input: "Fizz & buzz\n\ttabbed newline\rcarriage returned line\nbackspace character: \"\" form feed character: \" \"",
expectedOutput: "Fizz & buzz\\n\\ttabbed newline\\rcarriage returned line\\nbackspace character: \\\"\\b\\\" form feed character: \\\"\\f\\\"",
recipeConfig: [
{
"op": "Escape String",
"args": []
}
],
},
{
name: "Unescape String: quotes",
input: "Hello \\\"World\\\"! Escape \\'these\\' quotes.",
expectedOutput: "Hello \"World\"! Escape 'these' quotes.",
recipeConfig: [
{
"op": "Unescape String",
"args": []
}
],
},
{
name: "Unescape String: special characters",
input: "Fizz \x26 buzz\\n\\ttabbed newline\\rcarriage returned line\\nbackspace character: \\\"\\b\\\" form feed character: \\\"\\f\\\"",
expectedOutput: "Fizz & buzz\n\ttabbed newline\rcarriage returned line\nbackspace character: \"\" form feed character: \" \"",
recipeConfig: [
{
"op": "Unescape String",
"args": []
}
],
},
]);