Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Nov 23, 2023
1 parent b551d1f commit 011c96a
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 201 deletions.
207 changes: 106 additions & 101 deletions src/algos/fzf/fzf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,104 +588,109 @@ pub(super) fn compute_score<const RANGES: bool>(
score
}

// #[cfg(test)]
// mod tests {
// #![allow(clippy::single_range_in_vec_init)]
//
// use super::*;
//
// #[test]
// fn equal_match_1() {
// let pattern =
// Pattern::parse("^AbC$".chars().collect::<Vec<_>>().leak());
//
// let mut ranges_buf = MatchedRanges::default();
//
// assert!(exact_match(
// pattern,
// "ABC",
// todo!(),
// &Scheme::default(),
// Some(&mut ranges_buf)
// )
// .is_none());
//
// {
// ranges_buf = MatchedRanges::default();
//
// assert!(exact_match(
// pattern,
// "AbC",
// todo!(),
// &Scheme::default(),
// Some(&mut ranges_buf)
// )
// .is_some());
//
// assert_eq!(ranges_buf.as_slice(), [0..3]);
// }
//
// {
// ranges_buf = MatchedRanges::default();
//
// assert!(exact_match(
// pattern,
// "AbC ",
// todo!(),
// &Scheme::default(),
// Some(&mut ranges_buf)
// )
// .is_some());
//
// assert_eq!(ranges_buf.as_slice(), [0..3]);
// }
//
// {
// ranges_buf = MatchedRanges::default();
//
// assert!(exact_match(
// pattern,
// " AbC ",
// todo!(),
// &Scheme::default(),
// Some(&mut ranges_buf)
// )
// .is_some());
//
// assert_eq!(ranges_buf.as_slice(), [1..4]);
// }
//
// {
// ranges_buf = MatchedRanges::default();
//
// assert!(exact_match(
// pattern,
// " AbC",
// todo!(),
// &Scheme::default(),
// Some(&mut ranges_buf)
// )
// .is_some());
//
// assert_eq!(ranges_buf.as_slice(), [2..5]);
// }
// }
//
// #[test]
// fn exact_match_1() {
// let pattern = Pattern::parse("abc".chars().collect::<Vec<_>>().leak());
//
// let mut ranges_buf = MatchedRanges::default();
//
// assert!(exact_match(
// pattern,
// "aabbcc abc",
// todo!(),
// &Scheme::default(),
// Some(&mut ranges_buf)
// )
// .is_some());
//
// assert_eq!(ranges_buf.as_slice(), [7..10]);
// }
// }
#[cfg(test)]
mod tests {
#![allow(clippy::single_range_in_vec_init)]

use super::*;

fn candidate(s: &str) -> Candidate {
assert!(s.is_ascii());
Candidate::Ascii(s.as_bytes())
}

#[test]
fn equal_match_1() {
let pattern =
Pattern::parse("^AbC$".chars().collect::<Vec<_>>().leak());

let mut ranges_buf = MatchedRanges::default();

assert!(exact_match::<true>(
pattern,
candidate("ABC"),
utils::char_eq(false, false),
&Scheme::default(),
&mut ranges_buf
)
.is_none());

{
ranges_buf = MatchedRanges::default();

assert!(exact_match::<true>(
pattern,
candidate("AbC"),
utils::char_eq(false, false),
&Scheme::default(),
&mut ranges_buf
)
.is_some());

assert_eq!(ranges_buf.as_slice(), [0..3]);
}

{
ranges_buf = MatchedRanges::default();

assert!(exact_match::<true>(
pattern,
candidate("AbC "),
utils::char_eq(false, false),
&Scheme::default(),
&mut ranges_buf
)
.is_some());

assert_eq!(ranges_buf.as_slice(), [0..3]);
}

{
ranges_buf = MatchedRanges::default();

assert!(exact_match::<true>(
pattern,
candidate(" AbC "),
utils::char_eq(false, false),
&Scheme::default(),
&mut ranges_buf
)
.is_some());

assert_eq!(ranges_buf.as_slice(), [1..4]);
}

{
ranges_buf = MatchedRanges::default();

assert!(exact_match::<true>(
pattern,
candidate(" AbC"),
utils::char_eq(false, false),
&Scheme::default(),
&mut ranges_buf
)
.is_some());

assert_eq!(ranges_buf.as_slice(), [2..5]);
}
}

#[test]
fn exact_match_1() {
let pattern = Pattern::parse("abc".chars().collect::<Vec<_>>().leak());

let mut ranges_buf = MatchedRanges::default();

assert!(exact_match::<true>(
pattern,
candidate("aabbcc abc"),
utils::char_eq(false, false),
&Scheme::default(),
&mut ranges_buf
)
.is_some());

assert_eq!(ranges_buf.as_slice(), [7..10]);
}
}
6 changes: 6 additions & 0 deletions src/algos/fzf/fzf_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl FzfV1 {
Self::default()
}

/// TODO: docs
#[cfg(feature = "tests")]
pub fn scheme(&self) -> &Scheme {
&self.scheme
}

/// TODO: docs
#[inline(always)]
pub fn with_case_sensitivity(
Expand Down
6 changes: 6 additions & 0 deletions src/algos/fzf/fzf_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ impl FzfV2 {
Self::default()
}

/// TODO: docs
#[cfg(feature = "tests")]
pub fn scheme(&self) -> &Scheme {
&self.scheme
}

/// TODO: docs
#[inline(always)]
pub fn with_case_sensitivity(
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ mod utils;
pub use algos::*;
use candidate::{Candidate, CandidateMatches};
pub use case_sensitivity::CaseSensitivity;
use matched_ranges::MatchedRanges;
pub use matched_ranges::MatchedRanges;
pub use metric::Metric;
Loading

0 comments on commit 011c96a

Please sign in to comment.