pexpect test for commandline --current-process

It was not clear to me hwo this behaves when there are comments.

Include a friendly helper to compute control characters.
No functional change.
This commit is contained in:
Johannes Altmanninger 2020-03-29 18:34:08 +02:00
parent 108108bb5e
commit c6e1704f00
2 changed files with 48 additions and 1 deletions

View File

@ -341,3 +341,25 @@ class SpawnedProc(object):
"LIGHTCYAN": ansic(96), "LIGHTCYAN": ansic(96),
"WHITE": ansic(97), "WHITE": ansic(97),
} }
def control(char: str) -> str:
""" Returns the char sent when control is pressed along the given key. """
assert len(char) == 1
char = char.lower()
if ord("a") <= ord(char) <= ord("z"):
return chr(ord(char) - ord("a") + 1)
return chr({
"@": 0,
"`": 0,
"[": 27,
"{": 27,
"\\": 28,
"|": 28,
"]": 29,
"}": 29,
"^": 30,
"~": 30,
"_": 31,
"?": 127,
}[char])

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from pexpect_helper import SpawnedProc from pexpect_helper import SpawnedProc, control
sp = SpawnedProc() sp = SpawnedProc()
send, sendline, sleep, expect_prompt, expect_re, expect_str = ( send, sendline, sleep, expect_prompt, expect_re, expect_str = (
@ -59,3 +59,28 @@ send("\b" * 64)
# Commandline works when run on its own (#8807). # Commandline works when run on its own (#8807).
sendline("commandline whatever") sendline("commandline whatever")
expect_re("prompt [0-9]+>whatever") expect_re("prompt [0-9]+>whatever")
# Test --current-process output
send(control("u"))
sendline(r"bind \cb 'set tmp (commandline --current-process)'")
expect_prompt()
send("echo process1; echo process2")
send(control("a"))
send(control("b"))
send(control("k"))
sendline("echo first process is <$tmp>")
expect_str("first process is <echo process1>")
send("echo process # comment")
send(control("a"))
send(control("b"))
send(control("k"))
sendline('echo "process extent is <$tmp>"')
expect_str("process extent is <echo process # comment>")
sendline(r"bind \cb 'set tmp (commandline --current-process | count)'")
sendline(r'commandline "echo line1 \\" "# comment" "line2"')
send(control("b"))
send(control("u") * 6)
sendline('echo "process spans $tmp lines"')
expect_str("process spans 3 lines")