-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(auto_complete): Add codebase of auto-complete
- Loading branch information
Showing
8 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,68 @@ | ||
pub(crate) fn complete(input: &str, shell: impl Into<Shell>) -> String { | ||
let shell = shell.into(); | ||
|
||
// Load the runtime | ||
let (mut runtime, _scratch) = match shell { | ||
Shell::Bash => load_runtime::<completest_pty::BashRuntimeBuilder>(), | ||
Shell::Zsh => load_runtime::<completest_pty::ZshRuntimeBuilder>(), | ||
}; | ||
|
||
// Exec the completion | ||
let term = completest::Term::new(); | ||
let actual = runtime.complete(input, &term).unwrap(); | ||
|
||
actual | ||
} | ||
|
||
// Return the scratch directory to keep it not being dropped | ||
pub(crate) fn load_runtime<R: completest::RuntimeBuilder>( | ||
) -> (Box<dyn completest::Runtime>, snapbox::dir::DirRoot) | ||
where | ||
<R as completest::RuntimeBuilder>::Runtime: 'static, | ||
{ | ||
let shell_name = R::name(); | ||
|
||
let home = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("tests/testsuite/auto_complete/snapshots") | ||
.join(shell_name); | ||
|
||
let scratch = snapbox::dir::DirRoot::mutable_temp() | ||
.unwrap() | ||
.with_template(&home) | ||
.unwrap(); | ||
|
||
let home = scratch.path().unwrap().to_owned(); | ||
|
||
let bin_path = cargo_test_support::cargo_exe(); | ||
let bin_root = bin_path.parent().unwrap().to_owned(); | ||
|
||
let runtime = Box::new(R::with_home(bin_root, home).unwrap()); | ||
|
||
(runtime, scratch) | ||
} | ||
|
||
#[non_exhaustive] | ||
pub(crate) enum Shell { | ||
Bash, | ||
Zsh, | ||
} | ||
|
||
impl From<String> for Shell { | ||
fn from(value: String) -> Self { | ||
match value.as_str() { | ||
"bash" => Shell::Bash, | ||
"zsh" => Shell::Zsh, | ||
_ => panic!("Unsupported shell"), | ||
} | ||
} | ||
} | ||
|
||
impl From<&str> for Shell { | ||
fn from(value: &str) -> Self { | ||
match value { | ||
"bash" => Shell::Bash, | ||
"zsh" => Shell::Zsh, | ||
_ => panic!("Unsupported shell"), | ||
} | ||
} | ||
} |
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 @@ | ||
pub mod common; |
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,4 @@ | ||
PS1='% ' | ||
. /etc/bash_completion | ||
|
||
source <(CARGO_COMPLETE=bash cargo) |
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,5 @@ | ||
fpath=($fpath $ZDOTDIR/zsh) | ||
autoload -U +X compinit && compinit -u # bypass compaudit security checking | ||
precmd_functions="" # avoid the prompt being overwritten | ||
PS1='%% ' | ||
PROMPT='%% ' |
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,2 @@ | ||
#compdef cargo | ||
source <(CARGO_COMPLETE=zsh cargo) |
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