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 | |
13 | using namespace lldb_private; |
14 | |
15 | TEST(AnsiTerminal, Empty) { EXPECT_EQ("" , ansi::FormatAnsiTerminalCodes("" )); } |
16 | |
17 | TEST(AnsiTerminal, WhiteSpace) { |
18 | EXPECT_EQ(" " , ansi::FormatAnsiTerminalCodes(" " )); |
19 | } |
20 | |
21 | TEST(AnsiTerminal, AtEnd) { |
22 | EXPECT_EQ("abc\x1B[30m" , |
23 | ansi::FormatAnsiTerminalCodes("abc${ansi.fg.black}" )); |
24 | } |
25 | |
26 | TEST(AnsiTerminal, AtStart) { |
27 | EXPECT_EQ("\x1B[30mabc" , |
28 | ansi::FormatAnsiTerminalCodes("${ansi.fg.black}abc" )); |
29 | } |
30 | |
31 | TEST(AnsiTerminal, KnownPrefix) { |
32 | EXPECT_EQ("${ansi.fg.redish}abc" , |
33 | ansi::FormatAnsiTerminalCodes("${ansi.fg.redish}abc" )); |
34 | } |
35 | |
36 | TEST(AnsiTerminal, Unknown) { |
37 | EXPECT_EQ("${ansi.fg.foo}abc" , |
38 | ansi::FormatAnsiTerminalCodes("${ansi.fg.foo}abc" )); |
39 | } |
40 | |
41 | TEST(AnsiTerminal, Incomplete) { |
42 | EXPECT_EQ("abc${ansi." , ansi::FormatAnsiTerminalCodes("abc${ansi." )); |
43 | } |
44 | |
45 | TEST(AnsiTerminal, Twice) { |
46 | EXPECT_EQ("\x1B[30m\x1B[31mabc" , |
47 | ansi::FormatAnsiTerminalCodes("${ansi.fg.black}${ansi.fg.red}abc" )); |
48 | } |
49 | |
50 | TEST(AnsiTerminal, Basic) { |
51 | EXPECT_EQ( |
52 | "abc\x1B[31mabc\x1B[0mabc" , |
53 | ansi::FormatAnsiTerminalCodes("abc${ansi.fg.red}abc${ansi.normal}abc" )); |
54 | } |
55 | |