Skip to content

Commit

Permalink
test empty result
Browse files Browse the repository at this point in the history
  • Loading branch information
alpancs committed Sep 23, 2024
1 parent 2a9960f commit 6a0d632
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions quranize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,18 @@ impl Quranize {
}

pub fn encode(&self, s: &str) -> EncodeResults {
{
let s = normalization::normalize(s);
self.tree
.edges_from(0)
.flat_map(|&e| self.rev_encode(&s, e, None))
.collect::<Vec<_>>()
match normalization::normalize(s).as_str() {
"" => vec![],
s => { self.tree.edges_from(0) }
.flat_map(|&e| self.rev_encode(s, e, None))
.collect(),
}
.into_iter()
.chain({
let s = normalization::normalize_muqottoah(s);
self.tree
.edges_from(0)
.flat_map(|&e| self.rev_encode_muqottoah(&s, e))
.collect::<Vec<_>>()
.chain(match normalization::normalize_muqottoah(s).as_str() {
"" => vec![],
s => { self.tree.edges_from(0) }
.flat_map(|&e| self.rev_encode_muqottoah(s, e))
.collect(),
})
.map(|(q, n, e)| (q.chars().rev().collect(), n, e.into_iter().rev().collect()))
.collect()
Expand Down Expand Up @@ -201,6 +199,17 @@ mod tests {
assert_eq!(q.e("kaf ha ya 'ain shod"), &["كهيعص"]);
}

#[test]
fn test_quranize_empty_result() {
let q = Quranize::new();
let empty: [String; 0] = [];
assert_eq!(q.e(""), empty);
assert_eq!(q.e(" "), empty);
assert_eq!(q.e(" -"), empty);
assert_eq!(q.e("abcd"), empty);
assert_eq!(q.e("1+2=3"), empty);
}

#[test]
fn test_suffix_tree_props() {
let t = Quranize::new().tree;
Expand Down

0 comments on commit 6a0d632

Please sign in to comment.