1//===-- AnsiTerminalTest.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "gtest/gtest.h"
10
11#include "lldb/Utility/AnsiTerminal.h"
12
13using namespace lldb_private;
14
15TEST(AnsiTerminal, Empty) { EXPECT_EQ("", ansi::FormatAnsiTerminalCodes("")); }
16
17TEST(AnsiTerminal, WhiteSpace) {
18 EXPECT_EQ(" ", ansi::FormatAnsiTerminalCodes(" "));
19}
20
21TEST(AnsiTerminal, AtEnd) {
22 EXPECT_EQ("abc\x1B[30m",
23 ansi::FormatAnsiTerminalCodes("abc${ansi.fg.black}"));
24}
25
26TEST(AnsiTerminal, AtStart) {
27 EXPECT_EQ("\x1B[30mabc",
28 ansi::FormatAnsiTerminalCodes("${ansi.fg.black}abc"));
29}
30
31TEST(AnsiTerminal, KnownPrefix) {
32 EXPECT_EQ("${ansi.fg.redish}abc",
33 ansi::FormatAnsiTerminalCodes("${ansi.fg.redish}abc"));
34}
35
36TEST(AnsiTerminal, Unknown) {
37 EXPECT_EQ("${ansi.fg.foo}abc",
38 ansi::FormatAnsiTerminalCodes("${ansi.fg.foo}abc"));
39}
40
41TEST(AnsiTerminal, Incomplete) {
42 EXPECT_EQ("abc${ansi.", ansi::FormatAnsiTerminalCodes("abc${ansi."));
43}
44
45TEST(AnsiTerminal, Twice) {
46 EXPECT_EQ("\x1B[30m\x1B[31mabc",
47 ansi::FormatAnsiTerminalCodes("${ansi.fg.black}${ansi.fg.red}abc"));
48}
49
50TEST(AnsiTerminal, Basic) {
51 EXPECT_EQ(
52 "abc\x1B[31mabc\x1B[0mabc",
53 ansi::FormatAnsiTerminalCodes("abc${ansi.fg.red}abc${ansi.normal}abc"));
54}
55

source code of lldb/unittests/Utility/AnsiTerminalTest.cpp