mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-19 01:18:31 +08:00
Fix matching_words tests to compile successfully
The tests still fail due to a bug in https://github.com/meilisearch/tokenizer/pull/59
This commit is contained in:
parent
30247d70cd
commit
e752bd06f7
@ -182,8 +182,11 @@ fn bytes_to_highlight(source: &str, target: &str) -> usize {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
|
|
||||||
|
use meilisearch_tokenizer::TokenKind;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::search::query_tree::{Operation, Query, QueryKind};
|
use crate::search::query_tree::{Operation, Query, QueryKind};
|
||||||
use crate::MatchingWords;
|
use crate::MatchingWords;
|
||||||
@ -273,12 +276,61 @@ mod tests {
|
|||||||
|
|
||||||
let matching_words = MatchingWords::from_query_tree(&query_tree);
|
let matching_words = MatchingWords::from_query_tree(&query_tree);
|
||||||
|
|
||||||
assert_eq!(matching_words.matching_bytes("word"), Some(3));
|
assert_eq!(matching_words.matching_bytes(&Token{
|
||||||
assert_eq!(matching_words.matching_bytes("nyc"), None);
|
kind: TokenKind::Word,
|
||||||
assert_eq!(matching_words.matching_bytes("world"), Some(5));
|
word: Cow::Borrowed("word"),
|
||||||
assert_eq!(matching_words.matching_bytes("splitted"), Some(5));
|
byte_start: 0,
|
||||||
assert_eq!(matching_words.matching_bytes("thisnew"), None);
|
char_index: 0,
|
||||||
assert_eq!(matching_words.matching_bytes("borld"), Some(5));
|
byte_end: "word".len(),
|
||||||
assert_eq!(matching_words.matching_bytes("wordsplit"), Some(4));
|
char_map: None,
|
||||||
|
}), Some(3));
|
||||||
|
assert_eq!(matching_words.matching_bytes(&Token{
|
||||||
|
kind: TokenKind::Word,
|
||||||
|
word: Cow::Borrowed("nyc"),
|
||||||
|
byte_start: 0,
|
||||||
|
char_index: 0,
|
||||||
|
byte_end: "nyc".len(),
|
||||||
|
char_map: None,
|
||||||
|
}), None);
|
||||||
|
assert_eq!(matching_words.matching_bytes(&Token{
|
||||||
|
kind: TokenKind::Word,
|
||||||
|
word: Cow::Borrowed("world"),
|
||||||
|
byte_start: 0,
|
||||||
|
char_index: 0,
|
||||||
|
byte_end: "world".len(),
|
||||||
|
char_map: None,
|
||||||
|
}), Some(5));
|
||||||
|
assert_eq!(matching_words.matching_bytes(&Token{
|
||||||
|
kind: TokenKind::Word,
|
||||||
|
word: Cow::Borrowed("splitted"),
|
||||||
|
byte_start: 0,
|
||||||
|
char_index: 0,
|
||||||
|
byte_end: "splitted".len(),
|
||||||
|
char_map: None,
|
||||||
|
}), Some(5));
|
||||||
|
assert_eq!(matching_words.matching_bytes(&Token{
|
||||||
|
kind: TokenKind::Word,
|
||||||
|
word: Cow::Borrowed("thisnew"),
|
||||||
|
byte_start: 0,
|
||||||
|
char_index: 0,
|
||||||
|
byte_end: "thisnew".len(),
|
||||||
|
char_map: None,
|
||||||
|
}), None);
|
||||||
|
assert_eq!(matching_words.matching_bytes(&Token{
|
||||||
|
kind: TokenKind::Word,
|
||||||
|
word: Cow::Borrowed("borld"),
|
||||||
|
byte_start: 0,
|
||||||
|
char_index: 0,
|
||||||
|
byte_end: "borld".len(),
|
||||||
|
char_map: None,
|
||||||
|
}), Some(5));
|
||||||
|
assert_eq!(matching_words.matching_bytes(&Token{
|
||||||
|
kind: TokenKind::Word,
|
||||||
|
word: Cow::Borrowed("wordsplit"),
|
||||||
|
byte_start: 0,
|
||||||
|
char_index: 0,
|
||||||
|
byte_end: "wordsplit".len(),
|
||||||
|
char_map: None,
|
||||||
|
}), Some(4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user