Skip to content

Commit 04cbb17

Browse files
committed
test: dotnu_completions +2
1 parent 81203e1 commit 04cbb17

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

crates/nu-cli/src/completions/dotnu_completions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ impl Completer for DotNuCompletion {
3737

3838
let (base, partial) = if prefix_str == "~" {
3939
("~", "")
40-
} else if let Some((parent, remain)) = prefix_str.split_once(is_separator) {
40+
} else if let Some((parent, remain)) = prefix_str.rsplit_once(is_separator) {
4141
// If prefix_str is only a word we want to search in the current dir.
4242
// "/xx" should be split to "/" and "xx".
4343
if parent.is_empty() {
44-
("/", remain)
44+
(MAIN_SEPARATOR_STR, remain)
4545
} else {
4646
(parent, remain)
4747
}
@@ -125,7 +125,7 @@ impl Completer for DotNuCompletion {
125125
let mut span_offset = 0;
126126
let mut value = x.path.to_string();
127127
// Complete only the last path component
128-
if base_dir == "/" {
128+
if base_dir == MAIN_SEPARATOR_STR {
129129
span_offset = base_dir.len()
130130
} else if base_dir != "." {
131131
span_offset = base_dir.len() + 1

crates/nu-cli/tests/completions/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ fn dotnu_completions() {
343343
let suggestions = completer.complete(&completion_str, completion_str.len());
344344

345345
match_suggestions(&expected, &suggestions);
346+
347+
// Test special paths
348+
#[cfg(windows)]
349+
let completion_str = "use \\b".to_string();
350+
#[cfg(not(windows))]
351+
let completion_str = "use /b".to_string();
352+
let suggestions = completer.complete(&completion_str, completion_str.len());
353+
354+
assert!(!suggestions.is_empty());
355+
356+
let completion_str = "use ~".to_string();
357+
let suggestions = completer.complete(&completion_str, completion_str.len());
358+
359+
assert!(!suggestions.is_empty());
346360
}
347361

348362
#[test]

0 commit comments

Comments
 (0)