Extract test logic for computing and applying completion

Also move one test so all the bracket tests are contiguous.
This commit is contained in:
Johannes Altmanninger 2024-04-20 09:22:59 +02:00
parent 7dc0446c5c
commit a046b73ec7

View file

@ -133,37 +133,51 @@ fn test_complete() {
assert_eq!(completions.len(), 1); assert_eq!(completions.len(), 1);
assert_eq!(completions[0].completion, L!("space")); assert_eq!(completions[0].completion, L!("space"));
// Brackets - see #5831 macro_rules! unique_completion_applies_as {
completions = do_complete( ( $cmdline:expr, $completion_result:expr, $applied:expr $(,)? ) => {
L!("echo (ls test/complete_test/bracket["), let cmdline = L!($cmdline);
CompletionRequestOptions::default(), let completions = do_complete(cmdline, CompletionRequestOptions::default());
); assert_eq!(completions.len(), 1);
assert_eq!(completions.len(), 1); assert_eq!(
assert_eq!( completions[0].completion,
completions[0].completion, L!($completion_result),
L!("test/complete_test/bracket[abc]") "completion mismatch"
); );
let mut cursor = cmdline.len();
let newcmdline = completion_apply_to_command_line(
&completions[0].completion,
completions[0].flags,
cmdline,
&mut cursor,
false,
);
assert_eq!(newcmdline, L!($applied), "apply result mismatch");
};
}
let mut cmdline = L!("touch test/complete_test/bracket["); // Brackets - see #5831
completions = do_complete(cmdline, CompletionRequestOptions::default()); unique_completion_applies_as!(
assert_eq!(completions.len(), 1); "touch test/complete_test/bracket[",
assert_eq!( "test/complete_test/bracket[abc]",
completions[0].completion, "touch 'test/complete_test/bracket[abc]' ",
L!("test/complete_test/bracket[abc]")
); );
let mut cursor = cmdline.len(); unique_completion_applies_as!(
let newcmdline = completion_apply_to_command_line( "echo (ls test/complete_test/bracket[",
&completions[0].completion, "test/complete_test/bracket[abc]",
completions[0].flags, "echo (ls 'test/complete_test/bracket[abc]' ",
cmdline,
&mut cursor,
false,
); );
assert_eq!(newcmdline, L!("touch 'test/complete_test/bracket[abc]' ")); #[cfg(not(windows))] // Square brackets are not legal path characters on WIN32/CYGWIN
{
unique_completion_applies_as!(
r"touch test/complete_test/gnarlybracket\\[",
r"test/complete_test/gnarlybracket\[abc]",
r"touch 'test/complete_test/gnarlybracket\\[abc]' ",
);
}
// #8820 // #8820
let mut cursor_pos = 11; let mut cursor_pos = 11;
let mut newcmdline = completion_apply_to_command_line( let newcmdline = completion_apply_to_command_line(
L!("Debug/"), L!("Debug/"),
CompleteFlags::REPLACES_TOKEN | CompleteFlags::NO_SPACE, CompleteFlags::REPLACES_TOKEN | CompleteFlags::NO_SPACE,
L!("mv debug debug"), L!("mv debug debug"),
@ -172,29 +186,6 @@ fn test_complete() {
); );
assert_eq!(newcmdline, L!("mv debug Debug/")); assert_eq!(newcmdline, L!("mv debug Debug/"));
#[cfg(not(windows))] // Square brackets are not legal path characters on WIN32/CYGWIN
{
cmdline = L!(r"touch test/complete_test/gnarlybracket\\[");
completions = do_complete(cmdline, CompletionRequestOptions::default());
assert_eq!(completions.len(), 1);
assert_eq!(
completions[0].completion,
L!(r"test/complete_test/gnarlybracket\[abc]")
);
let mut cursor = cmdline.len();
newcmdline = completion_apply_to_command_line(
&completions[0].completion,
completions[0].flags,
cmdline,
&mut cursor,
false,
);
assert_eq!(
newcmdline,
L!(r"touch 'test/complete_test/gnarlybracket\\[abc]' ")
);
}
// Add a function and test completing it in various ways. // Add a function and test completing it in various ways.
parser.eval(L!("function scuttlebutt; end"), &IoChain::new()); parser.eval(L!("function scuttlebutt; end"), &IoChain::new());