diff --git a/src/algos/fzf/distance.rs b/src/algos/fzf/distance.rs index 7e12f31..4113e8b 100644 --- a/src/algos/fzf/distance.rs +++ b/src/algos/fzf/distance.rs @@ -4,6 +4,13 @@ use super::{Distance, Score}; #[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq)] pub struct FzfDistance(Distance); +impl Default for FzfDistance { + #[inline] + fn default() -> Self { + Self::from_score(0) + } +} + impl FzfDistance { /// TODO: docs #[inline] diff --git a/src/algos/fzf/v1.rs b/src/algos/fzf/v1.rs index 8d4f5b4..1125875 100644 --- a/src/algos/fzf/v1.rs +++ b/src/algos/fzf/v1.rs @@ -89,7 +89,7 @@ impl Metric for FzfV1 { candidate: &str, ) -> Option> { if query.is_empty() { - return None; + return Some(Match::default()); } let is_candidate_ascii = candidate.is_ascii(); diff --git a/src/algos/fzf/v2.rs b/src/algos/fzf/v2.rs index 8d8a306..ac63a6a 100644 --- a/src/algos/fzf/v2.rs +++ b/src/algos/fzf/v2.rs @@ -90,7 +90,7 @@ impl Metric for FzfV2 { candidate: &str, ) -> Option> { if query.is_empty() { - return None; + return Some(Match::default()); } let is_candidate_ascii = candidate.is_ascii(); diff --git a/src/match.rs b/src/match.rs index 4f132fe..7dbfcdd 100644 --- a/src/match.rs +++ b/src/match.rs @@ -3,6 +3,7 @@ use core::ops::Range; use crate::MatchedRanges; /// TODO: docs +#[derive(Default)] pub struct Match { /// TODO: docs distance: D, diff --git a/tests/fzf_common.rs b/tests/fzf_common.rs index 6e890f1..ddba1b3 100644 --- a/tests/fzf_common.rs +++ b/tests/fzf_common.rs @@ -4,9 +4,14 @@ use norm::fzf::{bonus, penalty}; use norm::CaseSensitivity; use CaseSensitivity::*; -pub fn empty_query() { +pub fn upstream_empty() { let (_, m) = fzf::(Insensitive, "", "foo"); - assert!(m.is_none()); + + let m = m.unwrap(); + + assert_eq!(m.distance().into_score(), 0); + + assert!(m.matched_ranges().is_empty()); } pub fn upstream_fuzzy_1() { diff --git a/tests/fzf_v1.rs b/tests/fzf_v1.rs index e56b887..24fe5d3 100644 --- a/tests/fzf_v1.rs +++ b/tests/fzf_v1.rs @@ -6,8 +6,8 @@ use fzf_common as common; use norm::fzf::FzfV1; #[test] -fn fzf_v1_empty_query() { - common::empty_query::(); +fn fzf_v1_upstream_empty() { + common::upstream_empty::(); } #[test] diff --git a/tests/fzf_v2.rs b/tests/fzf_v2.rs index 29f866b..b2902ee 100644 --- a/tests/fzf_v2.rs +++ b/tests/fzf_v2.rs @@ -8,8 +8,8 @@ use norm::fzf::{bonus, FzfParser, FzfV2}; use norm::{CaseSensitivity, Metric}; #[test] -fn fzf_v2_empty_query() { - common::empty_query::(); +fn fzf_v2_upstream_empty_1() { + common::upstream_empty::(); } #[test]