mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-01 15:14:26 +08:00
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:
parent
108108bb5e
commit
c6e1704f00
|
@ -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])
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user