2 Test that the lldb editline handling is configured correctly.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
10 from lldbsuite
.test
.lldbpexpect
import PExpectTest
13 class EditlineTest(PExpectTest
):
15 @skipIfEditlineSupportMissing
16 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"])
17 def test_left_right_arrow(self
):
18 """Test that ctrl+left/right arrow navigates words correctly.
20 Note: just sending escape characters to pexpect and checking the buffer
21 doesn't work well, so we run real commands. We want to type
22 "help command" while exercising word-navigation, so type it as below,
23 where [] indicates cursor position.
25 1. Send "el rint" -> "el rint[]"
26 2. Ctrl+left once -> "el []rint"
27 3. Send "p" -> "el p[]rint"
28 4. Ctrl+left twice -> "[]el print"
29 5. Send "h" -> "h[]el print"
30 6. Ctrl+right -> "hel[] print"
31 7. Send "p" -> "help print"
36 ("\x1b[1;5D", "\x1b[1;5C"),
37 ("\x1b[5D", "\x1b[5C"),
38 ("\x1b\x1b[D", "\x1b\x1b[C"),
40 for l_escape
, r_escape
in escape_pairs
:
42 "el rint{L}p{L}{L}h{R}p".format(L
=l_escape
, R
=r_escape
),
43 substrs
=["Syntax: print"],
49 @skipIfEditlineSupportMissing
50 @skipIfEditlineWideCharSupportMissing
51 def test_prompt_unicode(self
):
52 """Test that we can use Unicode in the LLDB prompt."""
53 self
.launch(use_colors
=True, encoding
="utf-8")
54 self
.child
.send('settings set prompt "🐛 "\n')
55 # Check that the cursor is at position 4 ([4G)
58 self
.child
.expect(re
.escape("🐛 \x1b[0m\x1b[4G"))
61 @skipIfEditlineSupportMissing
62 def test_prompt_color(self
):
63 """Test that we can change the prompt color with prompt-ansi-prefix."""
64 self
.launch(use_colors
=True)
65 self
.child
.send('settings set prompt-ansi-prefix "${ansi.fg.red}"\n')
66 # Make sure this change is reflected immediately. Check that the color
67 # is set (31) and the cursor position (8) is correct.
70 self
.child
.expect(re
.escape("\x1b[31m(lldb) \x1b[0m\x1b[8G"))
73 @skipIfEditlineSupportMissing
74 def test_prompt_no_color(self
):
75 """Test that prompt-ansi-prefix doesn't color the prompt when colors are off."""
76 self
.launch(use_colors
=False)
77 self
.child
.send('settings set prompt-ansi-prefix "${ansi.fg.red}"\n')
78 # Send foo so we can match the newline before the prompt and the foo
80 self
.child
.send("foo")
81 # Check that there are no escape codes.
82 self
.child
.expect(re
.escape("\n(lldb) foo"))