From c07ef049931b1f63a59d5cb3e907dc54028c282c Mon Sep 17 00:00:00 2001 From: ysthakur <45539777+ysthakur@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:45:05 -0400 Subject: [PATCH] Test #13302 --- .../src/completions/completion_common.rs | 23 ++++++++--------- crates/nu-cli/tests/completions/mod.rs | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/crates/nu-cli/src/completions/completion_common.rs b/crates/nu-cli/src/completions/completion_common.rs index 2b788b019b..6124ce3f1b 100644 --- a/crates/nu-cli/src/completions/completion_common.rs +++ b/crates/nu-cli/src/completions/completion_common.rs @@ -91,21 +91,20 @@ fn complete_rec( want_directory, isdir, )); + // For https://github.com/nushell/nushell/issues/13204 + if options.match_algorithm == MatchAlgorithm::Prefix { + let exact_match = if options.case_sensitive { + entry_name.eq(base) + } else { + entry_name.to_folded_case().eq(&base.to_folded_case()) + }; + if exact_match { + break; + } + } } else { completions.push(built); } - - // For https://github.com/nushell/nushell/issues/13204 - if isdir && options.match_algorithm == MatchAlgorithm::Prefix { - let exact_match = if options.case_sensitive { - entry_name.eq(base) - } else { - entry_name.to_folded_case().eq(&base.to_folded_case()) - }; - if exact_match { - break; - } - } } None => { completions.push(built); diff --git a/crates/nu-cli/tests/completions/mod.rs b/crates/nu-cli/tests/completions/mod.rs index e1714f78e2..b0559c78e5 100644 --- a/crates/nu-cli/tests/completions/mod.rs +++ b/crates/nu-cli/tests/completions/mod.rs @@ -1295,6 +1295,31 @@ fn sort_fuzzy_completions_in_alphabetical_order(mut fuzzy_alpha_sort_completer: ); } +#[test] +fn exact_match() { + let (dir, _, engine, stack) = new_partial_engine(); + + let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack)); + + let target_dir = format!("open {}", folder(dir.join("pArTiAL"))); + let suggestions = completer.complete(&target_dir, target_dir.len()); + + // Since it's an exact match, only 'partial' should be suggested, not + // 'partial-a' and stuff. Implemented in #13302 + match_suggestions( + &vec![file(dir.join("partial").join("hello.txt"))], + &suggestions, + ); + + let target_dir = format!("open {}", file(dir.join("pArTiAL").join("hello"))); + let suggestions = completer.complete(&target_dir, target_dir.len()); + + match_suggestions( + &vec![file(dir.join("partial").join("hello.txt"))], + &suggestions, + ); +} + #[ignore = "was reverted, still needs fixing"] #[rstest] fn alias_offset_bug_7648() {