+++ /dev/null
-// Copyright (C) 2021 Simon Ruderich
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package main
-
-import (
- "testing"
-
- "ruderich.org/simon/safcm/testutil"
-)
-
-func TestEscapeControlCharacters(t *testing.T) {
- tests := []struct {
- name string
- isTTY bool
- x string
- exp string
- }{
- {
- "UTF-8",
- false,
- "Hello, 世界",
- "Hello, 世界",
- },
- {
- "UTF-8 (TTY)",
- true,
- "Hello, 世界",
- "Hello, 世界",
- },
-
- {
- "color",
- false,
- ColorString(true, ColorRed, "red"),
- `\x1B[31mred\x1B[0m`,
- },
- {
- "color (TTY)",
- true,
- ColorString(true, ColorRed, "red"),
- "\x1B[35m\\x1B\x1B[0m[31mred\x1B[35m\\x1B\x1B[0m[0m",
- },
-
- {
- "\\r\\n",
- false,
- "\r\n",
- "\\r\n",
- },
- {
- "\\r\\n (TTY)",
- true,
- "\r\n",
- "\x1B[35m\\r\x1B[0m\n",
- },
-
- {
- "binary",
- false,
- "\xD6\x24\xA4\x45\xA2\x68\xD3\x0E\xD4\xC7\xC3\x1F",
- "\xD6$\xA4E\xA2h\xD3\\x0E\xD4\xC7\xC3\\x1F",
- },
- {
- "binary (TTY)",
- true,
- "\xD6\x24\xA4\x45\xA2\x68\xD3\x0E\xD4\xC7\xC3\x1F",
- "\xD6$\xA4E\xA2h\xD3\x1B[35m\\x0E\x1B[0m\xD4\xC7\xc3\x1B[35m\\x1F\x1B[0m",
- },
- }
-
- for _, tc := range tests {
- t.Run(tc.name, func(t *testing.T) {
- res := EscapeControlCharacters(tc.isTTY, tc.x)
- testutil.AssertEqual(t, "res", res, tc.exp)
- })
- }
-}