xref: /llvm-project/lldb/test/API/terminal/TestEditlineCompletions.py (revision 3dfc1d9b0bc41eaf63e551ca357b44a71636b152)
1import lldb
2from lldbsuite.test.decorators import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5from lldbsuite.test.lldbpexpect import PExpectTest
6
7
8class EditlineCompletionsTest(PExpectTest):
9    @skipIfAsan
10    @skipIfEditlineSupportMissing
11    def test_completion_truncated(self):
12        """Test that the completion is correctly truncated."""
13        self.launch(dimensions=(10, 20))
14        self.child.send("_regexp-\t")
15        self.child.expect("        _regexp-a...")
16        self.child.expect("        _regexp-b...")
17
18    @skipIfAsan
19    @skipIfEditlineSupportMissing
20    def test_description_truncated(self):
21        """Test that the description is correctly truncated."""
22        self.launch(dimensions=(10, 70))
23        self.child.send("_regexp-\t")
24        self.child.expect(
25            "        _regexp-attach    -- Attach to process by ID or name."
26        )
27        self.child.expect(
28            "        _regexp-break     -- Set a breakpoint using one of several..."
29        )
30
31    @skipIfAsan
32    @skipIfEditlineSupportMissing
33    def test_separator_omitted(self):
34        """Test that the separated is correctly omitted."""
35        self.launch(dimensions=(10, 32))
36        self.child.send("_regexp-\t")
37        self.child.expect("        _regexp-attach   \r\n")
38        self.child.expect("        _regexp-break    \r\n")
39
40    @skipIfAsan
41    @skipIfEditlineSupportMissing
42    def test_separator(self):
43        """Test that the separated is correctly printed."""
44        self.launch(dimensions=(10, 33))
45        self.child.send("_regexp-\t")
46        self.child.expect("        _regexp-attach    -- A...")
47        self.child.expect("        _regexp-break     -- S...")
48
49    @skipIfAsan
50    @skipIfEditlineSupportMissing
51    def test_multiline_description(self):
52        """Test that multi-line descriptions are correctly padded and truncated."""
53        self.launch(dimensions=(10, 72))
54        self.child.send("k\t")
55        self.child.expect(
56            "        kdp-remote -- Connect to a process via remote KDP server."
57        )
58        self.child.expect(
59            "                      If no UDP port is specified, port 41139 is assu..."
60        )
61        self.child.expect(
62            "                      kdp-remote is an abbreviation for 'process conn..."
63        )
64        self.child.expect("        kill       -- Terminate the current target process.")
65
66    @skipIfAsan
67    @skipIfEditlineSupportMissing
68    def test_completion_pagination(self):
69        """Test that we use the terminal height for pagination."""
70        self.launch(dimensions=(10, 30))
71        self.child.send("_regexp-\t")
72        self.child.expect("Available completions:")
73        self.child.expect("        _regexp-attach")
74        self.child.expect("        _regexp-break")
75        self.child.expect("        _regexp-bt")
76        self.child.expect("        _regexp-display")
77        self.child.expect("        _regexp-down")
78        self.child.expect("        _regexp-env")
79        self.child.expect("        _regexp-jump")
80        self.child.expect("More")
81
82    @skipIfAsan
83    @skipIfEditlineSupportMissing
84    def test_completion_multiline_pagination(self):
85        """Test that we use the terminal height for pagination and account for multi-line descriptions."""
86        self.launch(dimensions=(6, 72))
87        self.child.send("k\t")
88        self.child.expect("Available completions:")
89        self.child.expect(
90            "        kdp-remote -- Connect to a process via remote KDP server."
91        )
92        self.child.expect(
93            "                      If no UDP port is specified, port 41139 is assu..."
94        )
95        self.child.expect(
96            "                      kdp-remote is an abbreviation for 'process conn..."
97        )
98        self.child.expect("More")
99