-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
psh: add terminal control codes test
JIRA: CI-397
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Phoenix-RTOS | ||
# | ||
# phoenix-rtos-tests | ||
# | ||
# psh control codes test | ||
# | ||
# Copyright 2024 Phoenix Systems | ||
# Author: Damian Modzelewski | ||
# | ||
# This file is part of Phoenix-RTOS. | ||
# | ||
# %LICENSE% | ||
# | ||
|
||
import tools.psh as psh | ||
|
||
|
||
def CC_parser(harness, input: str, output: str): | ||
harness.write(input) | ||
if not output: | ||
harness.expect(psh.PROMPT) | ||
else: | ||
harness.expect(f"psh: {output} not found") | ||
|
||
|
||
""" | ||
CONTROL CODE CHEAT-SHEET | ||
(\177 or \033[3~) -> Delete the last character | ||
\001 -> Move to the first position in the text | ||
\003 -> Cancel command | ||
(\004 or \033[3~) -> Delete the next character after the cursor | ||
\005 -> Move to the last possible position | ||
(\002 or \033[D) -> Move the cursor to the left | ||
(\006 or \033[C) -> Move the cursor to the right | ||
\033[A -> In system declaration of Up arrow or 8 on numeric keypad | ||
\033[B -> In system declaration of Down arrow or 2 on numeric keypad | ||
\013 -> Cut text between cursor and end of line | ||
(\031 or \033[2~) -> Paste what is in the clipboard. The second one uses 0 on the numeric keypad. | ||
\027 -> Cut the last phrase before the cursor | ||
\025 -> Cut text between the beginning of the line and the cursor | ||
\033[1;5D -> Combination of keys CTRL + 4 on numeric keypad or left arrow to move the cursor to the left over phrases | ||
\033[1;5C -> Combination of keys CTRL + 6 on numeric keypad or right arrow to move the cursor to the left over phrases | ||
\t -> autocomplete path | ||
""" | ||
|
||
|
||
@psh.run | ||
def harness(p): | ||
# Trim the first three characters and put ABC after it move to start and put ABC | ||
CC_parser(p, "loremipsum\177\177\177\177\001ABC\005ABC\r", "ABCloremiABC") | ||
# Use the up arrow to redo the previous command | ||
CC_parser(p, "\033[A\r", "ABCloremiABC") | ||
# Use the up arrow to redo the previous command and back to the command passed at the beginning of the string | ||
CC_parser(p, "loremipsum\033[A\033[B\r", "loremipsum") | ||
# Move the cursor backward three paces and put ABC after it move one forward and put ABC | ||
CC_parser(p, "loremipsum\002\002\002\002ABC\006ABC\r", "loremiABCpABCsum") | ||
# Cancel command | ||
CC_parser(p, "loremipsum\003", "") | ||
# Cut the previous phrase before | ||
CC_parser(p, "lorem \027ipsum\r", "ipsum") | ||
# Paste the copied text | ||
CC_parser(p, "\031\r", "lorem") | ||
# Cut everything after the cursor | ||
CC_parser(p, "lorem\025ipsum\r", "ipsum") | ||
# Paste the copied text | ||
CC_parser(p, "\031\r", "lorem") | ||
# Move the cursor 5 times to the left and copy all after to the clipboard | ||
CC_parser(p, "loremipsum\033[D\033[D\033[D\033[D\033[D\013\r", "lorem") | ||
# Paste the copied text | ||
CC_parser(p, "\031\r", "ipsum") | ||
# Move the cursor 2 phrases before and cut everything before the cursor | ||
CC_parser(p, "lorem ipsum dolor\033[1;5D\033[1;5D\025\r", "ipsum") | ||
# Move the cursor to the start of the text and after that jump over the phrase, | ||
# remove whitespace and again jump. At the end copy all from the beginning to the cursor point | ||
CC_parser(p, "lorem ipsum dolor\001\033[1;5C\004\033[1;5C\025\r", "dolor") | ||
# Paste the copied text | ||
CC_parser(p, "\031\r", "loremipsum") | ||
# The cursor moves three spaces to the left and removes 3 characters after it | ||
CC_parser(p, "loremipsum\033[D\033[D\033[D\033[D\033[D\004\004\004\r", "loremum") | ||
# Move the cursor 3 characters to the left and cut everything from the beginning to it point | ||
CC_parser(p, "loremips u m\033[D\033[D\033[D\033[D\033[D\025\r", "s") | ||
# Paste the copied text | ||
CC_parser(p, "\031\r\n", "loremip") | ||
|
||
# Create a directory to check auto-completion | ||
psh.assert_cmd( | ||
p, | ||
"mkdir contorlcodetestdir ", | ||
result="success", | ||
msg="Failed to create dir", | ||
) | ||
# Trying to execute the previous folder with auto-completion | ||
p.sendline("/con\t") | ||
p.expect("psh: /contorlcodetestdir/ is not an executable") | ||
# Removing unnecessary directory | ||
psh.assert_cmd( | ||
p, "rm -d contorlcodetestdir", result="success", msg="Failed to delete dir" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters