1 // Copyright (C) 2021 Simon Ruderich
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 "ruderich.org/simon/safcm/testutil"
24 func TestEscapeControlCharacters(t *testing.T) {
47 ColorString(true, ColorRed, "red"),
53 ColorString(true, ColorRed, "red"),
54 "\x1B[35m\\x1B\x1B[0m[31mred\x1B[35m\\x1B\x1B[0m[0m",
67 "\x1B[35m\\r\x1B[0m\n",
73 "\xD6\x24\xA4\x45\xA2\x68\xD3\x0E\xD4\xC7\xC3\x1F",
74 "\xD6$\xA4E\xA2h\xD3\\x0E\xD4\xC7\xC3\\x1F",
79 "\xD6\x24\xA4\x45\xA2\x68\xD3\x0E\xD4\xC7\xC3\x1F",
80 "\xD6$\xA4E\xA2h\xD3\x1B[35m\\x0E\x1B[0m\xD4\xC7\xc3\x1B[35m\\x1F\x1B[0m",
84 for _, tc := range tests {
85 t.Run(tc.name, func(t *testing.T) {
86 res := EscapeControlCharacters(tc.isTTY, tc.x)
87 testutil.AssertEqual(t, "res", res, tc.exp)