123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- /**
- * StrUtils tests.
- *
- * @author n1474335 [n1474335@gmail.com]
- * @copyright Crown Copyright 2017
- * @license Apache-2.0
- */
- import TestRegister from "../../TestRegister.js";
- TestRegister.addTests([
- {
- 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: single quotes",
- input: "Escape 'these' quotes.",
- expectedOutput: "Escape \\'these\\' quotes.",
- recipeConfig: [
- {
- "op": "Escape string",
- "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]
- }
- ],
- },
- {
- 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": ["Special chars", "Double", false, true, false]
- }
- ],
- },
- {
- 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": []
- }
- ],
- },
- {
- 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": []
- }
- ],
- },
- ]);
|