Add test with special characters

This commit is contained in:
many 2021-07-01 16:44:17 +02:00
parent acfe31151e
commit 38161ede33
No known key found for this signature in database
GPG Key ID: 2CEF23B75189EACA

View File

@ -753,7 +753,7 @@ mod test {
/// https://github.com/meilisearch/MeiliSearch/issues/1368 /// https://github.com/meilisearch/MeiliSearch/issues/1368
#[test] #[test]
fn formatted_with_highlight_in_unicode_word() { fn formatted_with_highlight_emoji() {
let stop_words = fst::Set::default(); let stop_words = fst::Set::default();
let mut config = AnalyzerConfig::default(); let mut config = AnalyzerConfig::default();
config.stop_words(&stop_words); config.stop_words(&stop_words);
@ -816,6 +816,67 @@ mod test {
assert_eq!(value["author"], "JacobLey"); assert_eq!(value["author"], "JacobLey");
} }
#[test]
fn formatted_with_highlight_in_unicode_word() {
let stop_words = fst::Set::default();
let mut config = AnalyzerConfig::default();
config.stop_words(&stop_words);
let analyzer = Analyzer::new(config);
let formatter = Formatter::new(&analyzer, (String::from("<em>"), String::from("</em>")));
let mut fields = FieldsIdsMap::new();
let title = fields.insert("title").unwrap();
let author = fields.insert("author").unwrap();
let mut buf = Vec::new();
let mut obkv = obkv::KvWriter::new(&mut buf);
obkv.insert(title, Value::String("étoile".into()).to_string().as_bytes())
.unwrap();
obkv.finish().unwrap();
obkv = obkv::KvWriter::new(&mut buf);
obkv.insert(
author,
Value::String("J. R. R. Tolkien".into())
.to_string()
.as_bytes(),
)
.unwrap();
obkv.finish().unwrap();
let obkv = obkv::KvReader::new(&buf);
let mut formatted_options = BTreeMap::new();
formatted_options.insert(
title,
FormatOptions {
highlight: true,
crop: None,
},
);
formatted_options.insert(
author,
FormatOptions {
highlight: false,
crop: None,
},
);
let mut matching_words = BTreeMap::new();
matching_words.insert("etoile", Some(1));
let value = format_fields(
&fields,
obkv,
&formatter,
&matching_words,
&formatted_options,
)
.unwrap();
assert_eq!(value["title"], "<em>étoile</em>");
assert_eq!(value["author"], "J. R. R. Tolkien");
}
#[test] #[test]
fn formatted_with_crop_2() { fn formatted_with_crop_2() {
let stop_words = fst::Set::default(); let stop_words = fst::Set::default();