Change match_suggestions
as pass-by-reference to reuse expected values
This commit is contained in:
parent
656975e15a
commit
ae0da51368
|
@ -122,28 +122,28 @@ fn variables_double_dash_argument_with_flagcompletion(mut completer: NuCompleter
|
||||||
let suggestions = completer.complete("tst --", 6);
|
let suggestions = completer.complete("tst --", 6);
|
||||||
let expected: Vec<String> = vec!["--help".into(), "--mod".into()];
|
let expected: Vec<String> = vec!["--help".into(), "--mod".into()];
|
||||||
// dbg!(&expected, &suggestions);
|
// dbg!(&expected, &suggestions);
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn variables_single_dash_argument_with_flagcompletion(mut completer: NuCompleter) {
|
fn variables_single_dash_argument_with_flagcompletion(mut completer: NuCompleter) {
|
||||||
let suggestions = completer.complete("tst -", 5);
|
let suggestions = completer.complete("tst -", 5);
|
||||||
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
|
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn variables_command_with_commandcompletion(mut completer_strings: NuCompleter) {
|
fn variables_command_with_commandcompletion(mut completer_strings: NuCompleter) {
|
||||||
let suggestions = completer_strings.complete("my-c ", 4);
|
let suggestions = completer_strings.complete("my-c ", 4);
|
||||||
let expected: Vec<String> = vec!["my-command".into()];
|
let expected: Vec<String> = vec!["my-command".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn variables_subcommands_with_customcompletion(mut completer_strings: NuCompleter) {
|
fn variables_subcommands_with_customcompletion(mut completer_strings: NuCompleter) {
|
||||||
let suggestions = completer_strings.complete("my-command ", 11);
|
let suggestions = completer_strings.complete("my-command ", 11);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
|
@ -152,7 +152,7 @@ fn variables_customcompletion_subcommands_with_customcompletion_2(
|
||||||
) {
|
) {
|
||||||
let suggestions = completer_strings.complete("my-command ", 11);
|
let suggestions = completer_strings.complete("my-command ", 11);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -181,19 +181,19 @@ fn dotnu_completions() {
|
||||||
let completion_str = "source-env ".to_string();
|
let completion_str = "source-env ".to_string();
|
||||||
let suggestions = completer.complete(&completion_str, completion_str.len());
|
let suggestions = completer.complete(&completion_str, completion_str.len());
|
||||||
|
|
||||||
match_suggestions(expected.clone(), suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
// Test use completion
|
// Test use completion
|
||||||
let completion_str = "use ".to_string();
|
let completion_str = "use ".to_string();
|
||||||
let suggestions = completer.complete(&completion_str, completion_str.len());
|
let suggestions = completer.complete(&completion_str, completion_str.len());
|
||||||
|
|
||||||
match_suggestions(expected.clone(), suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
// Test overlay use completion
|
// Test overlay use completion
|
||||||
let completion_str = "overlay use ".to_string();
|
let completion_str = "overlay use ".to_string();
|
||||||
let suggestions = completer.complete(&completion_str, completion_str.len());
|
let suggestions = completer.complete(&completion_str, completion_str.len());
|
||||||
|
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -263,16 +263,16 @@ fn file_completions() {
|
||||||
let target_dir = format!("cp {dir_str}{separator}");
|
let target_dir = format!("cp {dir_str}{separator}");
|
||||||
let slash_suggestions = completer.complete(&target_dir, target_dir.len());
|
let slash_suggestions = completer.complete(&target_dir, target_dir.len());
|
||||||
|
|
||||||
let expected_slash_paths = expected_paths
|
let expected_slash_paths: Vec<String> = expected_paths
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.replace('\\', "/"))
|
.map(|s| s.replace('\\', "/"))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
match_suggestions(expected_slash_paths, slash_suggestions);
|
match_suggestions(&expected_slash_paths, &slash_suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
// Test completions for a file
|
// Test completions for a file
|
||||||
let target_dir = format!("cp {}", folder(dir.join("another")));
|
let target_dir = format!("cp {}", folder(dir.join("another")));
|
||||||
|
@ -282,7 +282,7 @@ fn file_completions() {
|
||||||
let expected_paths: Vec<String> = vec![file(dir.join("another").join("newfile"))];
|
let expected_paths: Vec<String> = vec![file(dir.join("another").join("newfile"))];
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
// Test completions for hidden files
|
// Test completions for hidden files
|
||||||
let target_dir = format!("ls {}{MAIN_SEPARATOR}.", folder(dir.join(".hidden_folder")));
|
let target_dir = format!("ls {}{MAIN_SEPARATOR}.", folder(dir.join(".hidden_folder")));
|
||||||
|
@ -296,16 +296,16 @@ fn file_completions() {
|
||||||
let target_dir = format!("ls {}/.", folder(dir.join(".hidden_folder")));
|
let target_dir = format!("ls {}/.", folder(dir.join(".hidden_folder")));
|
||||||
let slash_suggestions = completer.complete(&target_dir, target_dir.len());
|
let slash_suggestions = completer.complete(&target_dir, target_dir.len());
|
||||||
|
|
||||||
let expected_slash = expected_paths
|
let expected_slash: Vec<String> = expected_paths
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.replace('\\', "/"))
|
.map(|s| s.replace('\\', "/"))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
match_suggestions(expected_slash, slash_suggestions)
|
match_suggestions(&expected_slash, &slash_suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -329,7 +329,7 @@ fn partial_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
// Test completions for the files whose name begin with "h"
|
// Test completions for the files whose name begin with "h"
|
||||||
// and are present under directories whose names begin with "pa"
|
// and are present under directories whose names begin with "pa"
|
||||||
|
@ -350,7 +350,7 @@ fn partial_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
// Test completion for all files under directories whose names begin with "pa"
|
// Test completion for all files under directories whose names begin with "pa"
|
||||||
let dir_str = folder(dir.join("pa"));
|
let dir_str = folder(dir.join("pa"));
|
||||||
|
@ -371,7 +371,7 @@ fn partial_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
// Test completion for a single file
|
// Test completion for a single file
|
||||||
let dir_str = file(dir.join("fi").join("so"));
|
let dir_str = file(dir.join("fi").join("so"));
|
||||||
|
@ -382,7 +382,7 @@ fn partial_completions() {
|
||||||
let expected_paths: Vec<String> = vec![file(dir.join("final_partial").join("somefile"))];
|
let expected_paths: Vec<String> = vec![file(dir.join("final_partial").join("somefile"))];
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
// Test completion where there is a sneaky `..` in the path
|
// Test completion where there is a sneaky `..` in the path
|
||||||
let dir_str = file(dir.join("par").join("..").join("fi").join("so"));
|
let dir_str = file(dir.join("par").join("..").join("fi").join("so"));
|
||||||
|
@ -418,7 +418,7 @@ fn partial_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
// Test completion for all files under directories whose names begin with "pa"
|
// Test completion for all files under directories whose names begin with "pa"
|
||||||
let file_str = file(dir.join("partial-a").join("have"));
|
let file_str = file(dir.join("partial-a").join("have"));
|
||||||
|
@ -432,7 +432,7 @@ fn partial_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
// Test completion for all files under directories whose names begin with "pa"
|
// Test completion for all files under directories whose names begin with "pa"
|
||||||
let file_str = file(dir.join("partial-a").join("have_ext."));
|
let file_str = file(dir.join("partial-a").join("have_ext."));
|
||||||
|
@ -446,7 +446,7 @@ fn partial_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -481,14 +481,14 @@ fn command_ls_with_filecompletion() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
let target_dir = "ls custom_completion.";
|
let target_dir = "ls custom_completion.";
|
||||||
let suggestions = completer.complete(target_dir, target_dir.len());
|
let suggestions = completer.complete(target_dir, target_dir.len());
|
||||||
|
|
||||||
let expected_paths: Vec<String> = vec!["custom_completion.nu".to_string()];
|
let expected_paths: Vec<String> = vec!["custom_completion.nu".to_string()];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -523,14 +523,14 @@ fn command_open_with_filecompletion() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
let target_dir = "open custom_completion.";
|
let target_dir = "open custom_completion.";
|
||||||
let suggestions = completer.complete(target_dir, target_dir.len());
|
let suggestions = completer.complete(target_dir, target_dir.len());
|
||||||
|
|
||||||
let expected_paths: Vec<String> = vec!["custom_completion.nu".to_string()];
|
let expected_paths: Vec<String> = vec!["custom_completion.nu".to_string()];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -565,7 +565,7 @@ fn command_rm_with_globcompletion() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -600,7 +600,7 @@ fn command_cp_with_globcompletion() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -635,7 +635,7 @@ fn command_save_with_filecompletion() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -670,7 +670,7 @@ fn command_touch_with_filecompletion() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -705,7 +705,7 @@ fn command_watch_with_filecompletion() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
|
@ -713,19 +713,19 @@ fn subcommand_completions(mut subcommand_completer: NuCompleter) {
|
||||||
let prefix = "foo br";
|
let prefix = "foo br";
|
||||||
let suggestions = subcommand_completer.complete(prefix, prefix.len());
|
let suggestions = subcommand_completer.complete(prefix, prefix.len());
|
||||||
match_suggestions(
|
match_suggestions(
|
||||||
vec!["foo bar".to_string(), "foo aabrr".to_string()],
|
&vec!["foo bar".to_string(), "foo aabrr".to_string()],
|
||||||
suggestions,
|
&suggestions,
|
||||||
);
|
);
|
||||||
|
|
||||||
let prefix = "foo b";
|
let prefix = "foo b";
|
||||||
let suggestions = subcommand_completer.complete(prefix, prefix.len());
|
let suggestions = subcommand_completer.complete(prefix, prefix.len());
|
||||||
match_suggestions(
|
match_suggestions(
|
||||||
vec![
|
&vec![
|
||||||
"foo bar".to_string(),
|
"foo bar".to_string(),
|
||||||
"foo abaz".to_string(),
|
"foo abaz".to_string(),
|
||||||
"foo aabrr".to_string(),
|
"foo aabrr".to_string(),
|
||||||
],
|
],
|
||||||
suggestions,
|
&suggestions,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,7 +751,7 @@ fn file_completion_quoted() {
|
||||||
format!("`{}`", folder("test dir".into())),
|
format!("`{}`", folder("test dir".into())),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
|
|
||||||
let dir: PathBuf = "test dir".into();
|
let dir: PathBuf = "test dir".into();
|
||||||
let target_dir = format!("open '{}'", folder(dir.clone()));
|
let target_dir = format!("open '{}'", folder(dir.clone()));
|
||||||
|
@ -762,7 +762,7 @@ fn file_completion_quoted() {
|
||||||
format!("`{}`", file(dir.join("single quote"))),
|
format!("`{}`", file(dir.join("single quote"))),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -797,7 +797,7 @@ fn flag_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -826,16 +826,16 @@ fn folder_with_directorycompletions() {
|
||||||
let target_dir = format!("cd {dir_str}/");
|
let target_dir = format!("cd {dir_str}/");
|
||||||
let slash_suggestions = completer.complete(&target_dir, target_dir.len());
|
let slash_suggestions = completer.complete(&target_dir, target_dir.len());
|
||||||
|
|
||||||
let expected_slash_paths = expected_paths
|
let expected_slash_paths: Vec<String> = expected_paths
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.replace('\\', "/"))
|
.map(|s| s.replace('\\', "/"))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
match_suggestions(expected_slash_paths, slash_suggestions);
|
match_suggestions(&expected_slash_paths, &slash_suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match the results
|
// Match the results
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -877,7 +877,7 @@ fn variables_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
// Test completions for $nu.h (filter)
|
// Test completions for $nu.h (filter)
|
||||||
let suggestions = completer.complete("$nu.h", 5);
|
let suggestions = completer.complete("$nu.h", 5);
|
||||||
|
@ -891,7 +891,7 @@ fn variables_completions() {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
// Test completions for $nu.os-info
|
// Test completions for $nu.os-info
|
||||||
let suggestions = completer.complete("$nu.os-info.", 12);
|
let suggestions = completer.complete("$nu.os-info.", 12);
|
||||||
|
@ -903,7 +903,7 @@ fn variables_completions() {
|
||||||
"name".into(),
|
"name".into(),
|
||||||
];
|
];
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
// Test completions for custom var
|
// Test completions for custom var
|
||||||
let suggestions = completer.complete("$actor.", 7);
|
let suggestions = completer.complete("$actor.", 7);
|
||||||
|
@ -913,7 +913,7 @@ fn variables_completions() {
|
||||||
let expected: Vec<String> = vec!["age".into(), "name".into()];
|
let expected: Vec<String> = vec!["age".into(), "name".into()];
|
||||||
|
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
// Test completions for custom var (filtering)
|
// Test completions for custom var (filtering)
|
||||||
let suggestions = completer.complete("$actor.n", 8);
|
let suggestions = completer.complete("$actor.n", 8);
|
||||||
|
@ -923,7 +923,7 @@ fn variables_completions() {
|
||||||
let expected: Vec<String> = vec!["name".into()];
|
let expected: Vec<String> = vec!["name".into()];
|
||||||
|
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
// Test completions for $env
|
// Test completions for $env
|
||||||
let suggestions = completer.complete("$env.", 5);
|
let suggestions = completer.complete("$env.", 5);
|
||||||
|
@ -936,7 +936,7 @@ fn variables_completions() {
|
||||||
let expected: Vec<String> = vec!["PATH".into(), "PWD".into(), "TEST".into()];
|
let expected: Vec<String> = vec!["PATH".into(), "PWD".into(), "TEST".into()];
|
||||||
|
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
// Test completions for $env
|
// Test completions for $env
|
||||||
let suggestions = completer.complete("$env.T", 6);
|
let suggestions = completer.complete("$env.T", 6);
|
||||||
|
@ -946,12 +946,12 @@ fn variables_completions() {
|
||||||
let expected: Vec<String> = vec!["TEST".into()];
|
let expected: Vec<String> = vec!["TEST".into()];
|
||||||
|
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
|
|
||||||
let suggestions = completer.complete("$", 1);
|
let suggestions = completer.complete("$", 1);
|
||||||
let expected: Vec<String> = vec!["$actor".into(), "$env".into(), "$in".into(), "$nu".into()];
|
let expected: Vec<String> = vec!["$actor".into(), "$env".into(), "$in".into(), "$nu".into()];
|
||||||
|
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -970,7 +970,7 @@ fn alias_of_command_and_flags() {
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
|
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -989,7 +989,7 @@ fn alias_of_basic_command() {
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
|
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1011,7 +1011,7 @@ fn alias_of_another_alias() {
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
|
let expected_paths: Vec<String> = vec!["test_a/".to_string(), "test_b/".to_string()];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_external_completion(completer: &str, input: &str) -> Vec<Suggestion> {
|
fn run_external_completion(completer: &str, input: &str) -> Vec<Suggestion> {
|
||||||
|
@ -1074,35 +1074,35 @@ fn unknown_command_completion() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions)
|
match_suggestions(&expected_paths, &suggestions)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn flagcompletion_triggers_after_cursor(mut completer: NuCompleter) {
|
fn flagcompletion_triggers_after_cursor(mut completer: NuCompleter) {
|
||||||
let suggestions = completer.complete("tst -h", 5);
|
let suggestions = completer.complete("tst -h", 5);
|
||||||
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
|
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn customcompletion_triggers_after_cursor(mut completer_strings: NuCompleter) {
|
fn customcompletion_triggers_after_cursor(mut completer_strings: NuCompleter) {
|
||||||
let suggestions = completer_strings.complete("my-command c", 11);
|
let suggestions = completer_strings.complete("my-command c", 11);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn customcompletion_triggers_after_cursor_piped(mut completer_strings: NuCompleter) {
|
fn customcompletion_triggers_after_cursor_piped(mut completer_strings: NuCompleter) {
|
||||||
let suggestions = completer_strings.complete("my-command c | ls", 11);
|
let suggestions = completer_strings.complete("my-command c | ls", 11);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn flagcompletion_triggers_after_cursor_piped(mut completer: NuCompleter) {
|
fn flagcompletion_triggers_after_cursor_piped(mut completer: NuCompleter) {
|
||||||
let suggestions = completer.complete("tst -h | ls", 5);
|
let suggestions = completer.complete("tst -h | ls", 5);
|
||||||
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
|
let expected: Vec<String> = vec!["--help".into(), "--mod".into(), "-h".into(), "-s".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1136,77 +1136,77 @@ fn filecompletions_triggers_after_cursor() {
|
||||||
".hidden_folder/".to_string(),
|
".hidden_folder/".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
match_suggestions(expected_paths, suggestions);
|
match_suggestions(&expected_paths, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn extern_custom_completion_positional(mut extern_completer: NuCompleter) {
|
fn extern_custom_completion_positional(mut extern_completer: NuCompleter) {
|
||||||
let suggestions = extern_completer.complete("spam ", 5);
|
let suggestions = extern_completer.complete("spam ", 5);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn extern_custom_completion_long_flag_1(mut extern_completer: NuCompleter) {
|
fn extern_custom_completion_long_flag_1(mut extern_completer: NuCompleter) {
|
||||||
let suggestions = extern_completer.complete("spam --foo=", 11);
|
let suggestions = extern_completer.complete("spam --foo=", 11);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn extern_custom_completion_long_flag_2(mut extern_completer: NuCompleter) {
|
fn extern_custom_completion_long_flag_2(mut extern_completer: NuCompleter) {
|
||||||
let suggestions = extern_completer.complete("spam --foo ", 11);
|
let suggestions = extern_completer.complete("spam --foo ", 11);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn extern_custom_completion_long_flag_short(mut extern_completer: NuCompleter) {
|
fn extern_custom_completion_long_flag_short(mut extern_completer: NuCompleter) {
|
||||||
let suggestions = extern_completer.complete("spam -f ", 8);
|
let suggestions = extern_completer.complete("spam -f ", 8);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn extern_custom_completion_short_flag(mut extern_completer: NuCompleter) {
|
fn extern_custom_completion_short_flag(mut extern_completer: NuCompleter) {
|
||||||
let suggestions = extern_completer.complete("spam -b ", 8);
|
let suggestions = extern_completer.complete("spam -b ", 8);
|
||||||
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
let expected: Vec<String> = vec!["cat".into(), "dog".into(), "eel".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn extern_complete_flags(mut extern_completer: NuCompleter) {
|
fn extern_complete_flags(mut extern_completer: NuCompleter) {
|
||||||
let suggestions = extern_completer.complete("spam -", 6);
|
let suggestions = extern_completer.complete("spam -", 6);
|
||||||
let expected: Vec<String> = vec!["--foo".into(), "-b".into(), "-f".into()];
|
let expected: Vec<String> = vec!["--foo".into(), "-b".into(), "-f".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn custom_completer_triggers_cursor_before_word(mut custom_completer: NuCompleter) {
|
fn custom_completer_triggers_cursor_before_word(mut custom_completer: NuCompleter) {
|
||||||
let suggestions = custom_completer.complete("cmd foo bar", 8);
|
let suggestions = custom_completer.complete("cmd foo bar", 8);
|
||||||
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "".into()];
|
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn custom_completer_triggers_cursor_on_word_left_boundary(mut custom_completer: NuCompleter) {
|
fn custom_completer_triggers_cursor_on_word_left_boundary(mut custom_completer: NuCompleter) {
|
||||||
let suggestions = custom_completer.complete("cmd foo bar", 8);
|
let suggestions = custom_completer.complete("cmd foo bar", 8);
|
||||||
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "".into()];
|
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn custom_completer_triggers_cursor_next_to_word(mut custom_completer: NuCompleter) {
|
fn custom_completer_triggers_cursor_next_to_word(mut custom_completer: NuCompleter) {
|
||||||
let suggestions = custom_completer.complete("cmd foo bar", 11);
|
let suggestions = custom_completer.complete("cmd foo bar", 11);
|
||||||
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "bar".into()];
|
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "bar".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn custom_completer_triggers_cursor_after_word(mut custom_completer: NuCompleter) {
|
fn custom_completer_triggers_cursor_after_word(mut custom_completer: NuCompleter) {
|
||||||
let suggestions = custom_completer.complete("cmd foo bar ", 12);
|
let suggestions = custom_completer.complete("cmd foo bar ", 12);
|
||||||
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "bar".into(), "".into()];
|
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "bar".into(), "".into()];
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(&expected, &suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ignore = "was reverted, still needs fixing"]
|
#[ignore = "was reverted, still needs fixing"]
|
||||||
|
|
|
@ -185,7 +185,7 @@ pub fn new_partial_engine() -> (PathBuf, String, EngineState, Stack) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// match a list of suggestions with the expected values
|
// match a list of suggestions with the expected values
|
||||||
pub fn match_suggestions(expected: Vec<String>, suggestions: Vec<Suggestion>) {
|
pub fn match_suggestions(expected: &Vec<String>, suggestions: &Vec<Suggestion>) {
|
||||||
let expected_len = expected.len();
|
let expected_len = expected.len();
|
||||||
let suggestions_len = suggestions.len();
|
let suggestions_len = suggestions.len();
|
||||||
if expected_len != suggestions_len {
|
if expected_len != suggestions_len {
|
||||||
|
@ -195,13 +195,13 @@ pub fn match_suggestions(expected: Vec<String>, suggestions: Vec<Suggestion>) {
|
||||||
Expected: {expected:#?}\n"
|
Expected: {expected:#?}\n"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
assert_eq!(
|
|
||||||
expected,
|
let suggestoins_str = suggestions
|
||||||
suggestions
|
.iter()
|
||||||
.into_iter()
|
.map(|it| it.value.clone())
|
||||||
.map(|it| it.value)
|
.collect::<Vec<_>>();
|
||||||
.collect::<Vec<_>>()
|
|
||||||
);
|
assert_eq!(expected, &suggestoins_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// append the separator to the converted path
|
// append the separator to the converted path
|
||||||
|
|
Loading…
Reference in New Issue
Block a user