Test if dotnu completions are sorted
This commit is contained in:
parent
2dd0963c44
commit
1919139836
|
@ -11,7 +11,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
use support::{
|
||||
completions_helpers::{new_partial_engine, new_quote_engine},
|
||||
completions_helpers::{new_dotnu_engine, new_partial_engine, new_quote_engine},
|
||||
file, folder, match_suggestions, new_engine,
|
||||
};
|
||||
|
||||
|
@ -138,7 +138,7 @@ fn variables_customcompletion_subcommands_with_customcompletion_2(
|
|||
#[test]
|
||||
fn dotnu_completions() {
|
||||
// Create a new engine
|
||||
let (_, _, engine, stack) = new_engine();
|
||||
let (_, _, engine, stack) = new_dotnu_engine();
|
||||
|
||||
// Instantiate a new completer
|
||||
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
|
||||
|
@ -147,12 +147,19 @@ fn dotnu_completions() {
|
|||
let completion_str = "source-env ".to_string();
|
||||
let suggestions = completer.complete(&completion_str, completion_str.len());
|
||||
|
||||
assert_eq!(2, suggestions.len());
|
||||
assert_eq!("custom_completion.nu", suggestions.first().unwrap().value);
|
||||
#[cfg(windows)]
|
||||
assert_eq!("directory_completion\\", suggestions.get(1).unwrap().value);
|
||||
#[cfg(not(windows))]
|
||||
assert_eq!("directory_completion/", suggestions.get(1).unwrap().value);
|
||||
match_suggestions(
|
||||
vec![
|
||||
"asdf.nu".into(),
|
||||
"bar.nu".into(),
|
||||
"bat.nu".into(),
|
||||
"baz.nu".into(),
|
||||
"dir_module/".into(),
|
||||
"foo.nu".into(),
|
||||
"spam.nu".into(),
|
||||
"xyzzy.nu".into(),
|
||||
],
|
||||
suggestions,
|
||||
);
|
||||
|
||||
// Test use completion
|
||||
let completion_str = "use ".to_string();
|
||||
|
|
|
@ -68,6 +68,52 @@ pub fn new_engine() -> (PathBuf, String, EngineState, Stack) {
|
|||
(dir, dir_str, engine_state, stack)
|
||||
}
|
||||
|
||||
// creates a new engine with the current path into the completions fixtures folder
|
||||
pub fn new_dotnu_engine() -> (PathBuf, String, EngineState, Stack) {
|
||||
// Target folder inside assets
|
||||
let dir = fs::fixtures().join("dotnu_completions");
|
||||
let dir_str = dir
|
||||
.clone()
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.unwrap_or_default();
|
||||
let dir_span = nu_protocol::Span::new(0, dir_str.len());
|
||||
|
||||
// Create a new engine with default context
|
||||
let mut engine_state = create_default_context();
|
||||
|
||||
// Add $nu
|
||||
engine_state.generate_nu_constant();
|
||||
|
||||
// New stack
|
||||
let mut stack = Stack::new();
|
||||
|
||||
// Add pwd as env var
|
||||
stack.add_env_var("PWD".to_string(), Value::string(dir_str.clone(), dir_span));
|
||||
stack.add_env_var(
|
||||
"TEST".to_string(),
|
||||
Value::string("NUSHELL".to_string(), dir_span),
|
||||
);
|
||||
|
||||
stack.add_env_var(
|
||||
"NU_LIB_DIRS".to_string(),
|
||||
Value::List {
|
||||
vals: vec![
|
||||
Value::string(file(dir.join("lib-dir1")), dir_span),
|
||||
Value::string(file(dir.join("lib-dir2")), dir_span),
|
||||
Value::string(file(dir.join("lib-dir3")), dir_span),
|
||||
],
|
||||
internal_span: dir_span,
|
||||
},
|
||||
);
|
||||
|
||||
// Merge environment into the permanent state
|
||||
let merge_result = engine_state.merge_env(&mut stack, &dir);
|
||||
assert!(merge_result.is_ok());
|
||||
|
||||
(dir, dir_str, engine_state, stack)
|
||||
}
|
||||
|
||||
pub fn new_quote_engine() -> (PathBuf, String, EngineState, Stack) {
|
||||
// Target folder inside assets
|
||||
let dir = fs::fixtures().join("quoted_completions");
|
||||
|
|
0
tests/fixtures/dotnu_completions/dir_module/mod.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/dir_module/mod.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/foo.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/foo.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir1/bar.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir1/bar.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir1/baz.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir1/baz.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir1/xyzzy.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir1/xyzzy.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir2/asdf.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir2/asdf.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir2/bat.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir2/bat.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir3/spam.nu
vendored
Normal file
0
tests/fixtures/dotnu_completions/lib-dir3/spam.nu
vendored
Normal file
Loading…
Reference in New Issue
Block a user