1 | "use strict";
|
2 |
|
3 | module.exports = function (t, a) {
|
4 | var slice = t;
|
5 |
|
6 | a(typeof slice, "function");
|
7 |
|
8 | a(slice("ABCDE", 1), "BCDE", "Works on plain string");
|
9 | a(slice("ABCDE", -1), "E", "Works on plain string");
|
10 | a(slice("ABCDE", 1, 3), "BC", "Works on plain string");
|
11 | a(slice("ABCDE", -3, -1), "CD", "Works on plain string");
|
12 |
|
13 | a(
|
14 | slice("\x1b[31mABCDE\x1b[39m", 1), "\x1b[31mBCDE\x1b[39m",
|
15 | "Works on whole single forecolor-styled string"
|
16 | );
|
17 | a(
|
18 | slice("\x1b[31mABCDE\x1b[39m", -1), "\x1b[31mE\x1b[39m",
|
19 | "Works on whole single forecolor-styled string"
|
20 | );
|
21 | a(
|
22 | slice("\x1b[31mABCDE\x1b[39m", 1, 3), "\x1b[31mBC\x1b[39m",
|
23 | "Works on whole single forecolor-styled string"
|
24 | );
|
25 | a(
|
26 | slice("\x1b[31mABCDE\x1b[39m", -3, -1), "\x1b[31mCD\x1b[39m",
|
27 | "Works on whole single forecolor-styled string"
|
28 | );
|
29 |
|
30 | a(
|
31 | slice("\x1b[41mABCDE\x1b[49m", 1), "\x1b[41mBCDE\x1b[49m",
|
32 | "Works on whole single backcolor-styled string"
|
33 | );
|
34 | a(
|
35 | slice("\x1b[41mABCDE\x1b[49m", -1), "\x1b[41mE\x1b[49m",
|
36 | "Works on whole single backcolor-styled string"
|
37 | );
|
38 | a(
|
39 | slice("\x1b[41mABCDE\x1b[49m", 1, 3), "\x1b[41mBC\x1b[49m",
|
40 | "Works on whole single backcolor-styled string"
|
41 | );
|
42 | a(
|
43 | slice("\x1b[41mABCDE\x1b[49m", -3, -1), "\x1b[41mCD\x1b[49m",
|
44 | "Works on whole single backcolor-styled string"
|
45 | );
|
46 |
|
47 | a(
|
48 | slice("ABC\x1b[31mDEF\x1b[39m", 0, 5), "ABC\x1b[31mDE\x1b[39m",
|
49 | "Save styles when chopping part of the forecolor-styled string"
|
50 | );
|
51 | a(
|
52 | slice("ABC\x1b[31mDEF\x1b[39m", 1, 4), "BC\x1b[31mD\x1b[39m",
|
53 | "Save styles when chopping part of the forecolor-styled string"
|
54 | );
|
55 | a(
|
56 | slice("ABC\x1b[31mDEF\x1b[39m", 1, 6), "BC\x1b[31mDEF\x1b[39m",
|
57 | "Save styles when chopping part of the forecolor-styled string"
|
58 | );
|
59 | a(
|
60 | slice("ABC\x1b[31mDEF\x1b[39m", -5, -1), "BC\x1b[31mDE\x1b[39m",
|
61 | "Save styles when chopping part of the forecolor-styled string"
|
62 | );
|
63 |
|
64 | a(
|
65 | slice("ABC\x1b[41mDEF\x1b[49m", 0, 5), "ABC\x1b[41mDE\x1b[49m",
|
66 | "Save styles when chopping part of the backcolor-styled string"
|
67 | );
|
68 | a(
|
69 | slice("ABC\x1b[41mDEF\x1b[49m", 1, 4), "BC\x1b[41mD\x1b[49m",
|
70 | "Save styles when chopping part of the backcolor-styled string"
|
71 | );
|
72 | a(
|
73 | slice("ABC\x1b[41mDEF\x1b[49m", 1, 6), "BC\x1b[41mDEF\x1b[49m",
|
74 | "Save styles when chopping part of the backcolor-styled string"
|
75 | );
|
76 | a(
|
77 | slice("ABC\x1b[41mDEF\x1b[49m", -5, -1), "BC\x1b[41mDE\x1b[49m",
|
78 | "Save styles when chopping part of the backcolor-styled string"
|
79 | );
|
80 |
|
81 | a(
|
82 | slice("\x1b[1mAAA\x1b[31mBBB\x1b[39mAAA\x1b[22m", 0, 5),
|
83 | "\x1b[1mAAA\x1b[31mBB\x1b[39m\x1b[22m", "Works with nested styles #1"
|
84 | );
|
85 | a(
|
86 | slice("\x1b[1mAAA\x1b[31mBBB\x1b[39mAAA\x1b[22m", 2, 7),
|
87 | "\x1b[1mA\x1b[31mBBB\x1b[39mA\x1b[22m", "Works with nested styles #2"
|
88 | );
|
89 | a(
|
90 | slice("\x1b[3mAAA\x1b[41mBBB\x1b[49mAAA\x1b[23m", 0, 5),
|
91 | "\x1b[3mAAA\x1b[41mBB\x1b[49m\x1b[23m", "Works with nested styles #3"
|
92 | );
|
93 | a(
|
94 | slice("\x1b[3mAAA\x1b[41mBBB\x1b[49mAAA\x1b[23m", 2, 7),
|
95 | "\x1b[3mA\x1b[41mBBB\x1b[49mA\x1b[23m", "Works with nested styles #4"
|
96 | );
|
97 | a(
|
98 | slice("\x1b[3mAAA\x1b[41mBBB\x1b[49mAAA\x1b[23m", -8, -1),
|
99 | "\x1b[3mAA\x1b[41mBBB\x1b[49mAA\x1b[23m", "Works with nested styles #5"
|
100 | );
|
101 |
|
102 | a(
|
103 | slice("\x1b[31mAAA\x1b[32mBBB\x1b[31mAAA\x1b[39m", 0, 5), "\x1b[31mAAA\x1b[32mBB\x1b[39m",
|
104 | "Works with nested overlapping styles #1"
|
105 | );
|
106 | a(
|
107 | slice("\x1b[31mAAA\x1b[32mBBB\x1b[31mAAA\x1b[39m", 2, 7),
|
108 | "\x1b[31mA\x1b[32mBBB\x1b[31mA\x1b[39m", "Works with nested overlapping styles #2"
|
109 | );
|
110 | a(
|
111 | slice("\x1b[31mAAA\x1b[32mBBB\x1b[31mAAA\x1b[39m", -8, -1),
|
112 | "\x1b[31mAA\x1b[32mBBB\x1b[31mAA\x1b[39m", "Works with nested overlapping styles #3"
|
113 | );
|
114 |
|
115 |
|
116 | a(slice("ABC\x1b[31mDEF\x1b[39m", 3), "\x1b[31mDEF\x1b[39m", "Does not corrupt start CSI");
|
117 | a(slice("\x1b[41mABC\x1b[49mDEF", 0, 3), "\x1b[41mABC\x1b[49m", "Does not corrupt end CSI");
|
118 |
|
119 |
|
120 | a(slice("ABC\x1b[31mDEF\x1b[39m", 0, 3), "ABC", "Does not mixin CSI to plain string");
|
121 | a(slice("ABCD\x1b[31mEF\x1b[39m", 0, 3), "ABC", "Does not mixin CSI to plain string");
|
122 | a(slice("\x1b[41mABC\x1b[49mDEF", 3), "DEF", "Does not mixin CSI to plain string");
|
123 | a(slice("\x1b[41mAB\x1b[49mCDEF", 3), "DEF", "Does not mixin CSI to plain string");
|
124 |
|
125 | a(
|
126 | slice("A\x1b[31mBBB\x1b[39mD\x1b[32mE\x1b[39m", 2, 3), "\x1b[31mB\x1b[39m",
|
127 | "Does slice with surrounding styles"
|
128 | );
|
129 | a(
|
130 | slice("A\x1b[31mBBB\x1b[39mD\x1b[32mE\x1b[39m", 0, 5), "A\x1b[31mBBB\x1b[39mD",
|
131 | "Does slice with inner styles"
|
132 | );
|
133 |
|
134 | a(
|
135 | slice("A\x1b[31mBBB\x1b[39m\x1b[2J\x1b[0;0H", 0, 4), "A\x1b[31mBBB\x1b[39m",
|
136 | "Remove reset CSI"
|
137 | );
|
138 |
|
139 |
|
140 | a(
|
141 | slice("A\u001b[31mBBB\u001b[39m\u001b[2J\u001b[1;1H", 0, 4), "A\x1b[31mBBB\x1b[39m",
|
142 | "Remove control CSIs"
|
143 | );
|
144 | };
|