2017-03-01 22:33:28 +01:00
|
|
|
|
/**
|
|
|
|
|
* StrUtils tests.
|
|
|
|
|
*
|
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
|
* @copyright Crown Copyright 2017
|
|
|
|
|
* @license Apache-2.0
|
|
|
|
|
*/
|
2018-05-17 17:34:00 +02:00
|
|
|
|
import TestRegister from "../../TestRegister";
|
2017-03-21 23:41:44 +01:00
|
|
|
|
|
2017-03-01 22:33:28 +01:00
|
|
|
|
TestRegister.addTests([
|
2017-03-27 20:39:04 +02:00
|
|
|
|
{
|
|
|
|
|
name: "Diff, basic usage",
|
|
|
|
|
input: "testing23\n\ntesting123",
|
2017-07-17 15:31:28 +02:00
|
|
|
|
expectedOutput: "testing<span class='hl5'>1</span>23",
|
2017-03-27 20:39:04 +02:00
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Diff",
|
|
|
|
|
"args": ["\\n\\n", "Character", true, true, false]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
2017-04-22 05:06:59 +02:00
|
|
|
|
{
|
|
|
|
|
name: "Head 0",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Head",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 0]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Head 1",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [1].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Head",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 1]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Head 2",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [1, 2].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Head",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 2]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Head 6",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Head",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 6]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Head big",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Head",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 100]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", -1]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Head all but 2",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [1, 2, 3, 4].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Head",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", -2]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Head all but 6",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Head",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", -6]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Head all but big",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Head",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", -100]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail 0",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 0]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail 1",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [6].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 1]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail 2",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [5, 6].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 2]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail 6",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 6]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail big",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", 100]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail all but 1",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
2017-04-23 19:29:54 +02:00
|
|
|
|
expectedOutput: [2, 3, 4, 5, 6].join("\n"),
|
2017-04-22 05:06:59 +02:00
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", -1]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail all but 2",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
2017-04-23 19:29:54 +02:00
|
|
|
|
expectedOutput: [3, 4, 5, 6].join("\n"),
|
2017-04-22 05:06:59 +02:00
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", -2]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail all but 6",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
2017-04-23 19:29:54 +02:00
|
|
|
|
expectedOutput: [].join("\n"),
|
2017-04-22 05:06:59 +02:00
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", -6]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Tail all but big",
|
|
|
|
|
input: [1, 2, 3, 4, 5, 6].join("\n"),
|
|
|
|
|
expectedOutput: [].join("\n"),
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Tail",
|
2017-04-23 19:29:54 +02:00
|
|
|
|
"args": ["Line feed", -100]
|
2017-04-22 05:06:59 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
2017-08-07 17:08:50 +02:00
|
|
|
|
{
|
2018-03-26 23:25:36 +02:00
|
|
|
|
name: "Escape String: single quotes",
|
|
|
|
|
input: "Escape 'these' quotes.",
|
|
|
|
|
expectedOutput: "Escape \\'these\\' quotes.",
|
2017-08-07 17:08:50 +02:00
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
2017-08-15 19:32:21 +02:00
|
|
|
|
"op": "Escape string",
|
2018-03-26 23:25:36 +02:00
|
|
|
|
"args": ["Special chars", "Single", false, true, false]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Escape String: double quotes",
|
|
|
|
|
input: "Hello \"World\"!",
|
|
|
|
|
expectedOutput: "Hello \\\"World\\\"!",
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Escape string",
|
|
|
|
|
"args": ["Special chars", "Double", false, true, false]
|
2017-08-07 17:08:50 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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: [
|
|
|
|
|
{
|
2017-08-15 19:32:21 +02:00
|
|
|
|
"op": "Escape string",
|
2018-03-26 23:25:36 +02:00
|
|
|
|
"args": ["Special chars", "Double", false, true, false]
|
2017-08-07 17:08:50 +02:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Unescape String: quotes",
|
|
|
|
|
input: "Hello \\\"World\\\"! Escape \\'these\\' quotes.",
|
|
|
|
|
expectedOutput: "Hello \"World\"! Escape 'these' quotes.",
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
2017-08-15 19:32:21 +02:00
|
|
|
|
"op": "Unescape string",
|
2017-08-07 17:08:50 +02:00
|
|
|
|
"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: [
|
|
|
|
|
{
|
2017-08-15 19:32:21 +02:00
|
|
|
|
"op": "Unescape string",
|
2017-08-07 17:08:50 +02:00
|
|
|
|
"args": []
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
2018-03-26 23:25:36 +02:00
|
|
|
|
{
|
|
|
|
|
name: "Escape String: complex",
|
|
|
|
|
input: "null\0backspace\btab\tnewline\nverticaltab\vformfeed\fcarriagereturn\rdoublequote\"singlequote'hex\xa9unicode\u2665codepoint\u{1D306}",
|
|
|
|
|
expectedOutput: "null\\0backspace\\btab\\tnewline\\nverticaltab\\x0bformfeed\\fcarriagereturn\\rdoublequote\"singlequote\\'hex\\xa9unicode\\u2665codepoint\\u{1d306}",
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Escape string",
|
|
|
|
|
"args": ["Special chars", "Single", false, true, false]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Unescape String: complex",
|
|
|
|
|
input: "null\\0backspace\\btab\\tnewline\\nverticaltab\\vformfeed\\fcarriagereturn\\rdoublequote\\\"singlequote\\'hex\\xa9unicode\\u2665codepoint\\u{1D306}",
|
|
|
|
|
expectedOutput: "null\0backspace\btab\tnewline\nverticaltab\vformfeed\fcarriagereturn\rdoublequote\"singlequote'hex\xa9unicode\u2665codepoint\u{1D306}",
|
|
|
|
|
recipeConfig: [
|
|
|
|
|
{
|
|
|
|
|
"op": "Unescape string",
|
|
|
|
|
"args": []
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
2017-03-01 22:33:28 +01:00
|
|
|
|
]);
|