diff --git a/milli/src/search/matches/mod.rs b/milli/src/search/matches/mod.rs
index 72592c4cb..09ed24080 100644
--- a/milli/src/search/matches/mod.rs
+++ b/milli/src/search/matches/mod.rs
@@ -573,15 +573,18 @@ mod tests {
let text = "Natalie risk her future to build a world with the boy she loves. Emily Henry: The Love That Split The World.";
let mut matcher = builder.build(text);
// no crop should return complete text with highlighted matches.
- assert_eq!(&matcher.format(format_options), "Natalie risk her future to build a world with the boy she loves. Emily Henry: The Love That Split The World.");
-
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"Natalie risk her future to build a world with the boy she loves. Emily Henry: The Love That Split The World."
+ );
+
// Text containing some matches.
let text = "Natalie risk her future to build a world with the boy she loves.";
let mut matcher = builder.build(text);
// no crop should return complete text with highlighted matches.
- assert_eq!(
- &matcher.format(format_options),
- "Natalie risk her future to build a world with the boy she loves."
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"Natalie risk her future to build a world with the boy she loves."
);
}
@@ -602,19 +605,28 @@ mod tests {
let text = "Ŵôřlḑôle";
let mut matcher = builder.build(text);
// no crop should return complete text with highlighted matches.
- assert_eq!(&matcher.format(format_options), "Ŵôřlḑôle");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"Ŵôřlḑôle"
+ );
// Text containing unicode match.
let text = "Ŵôřlḑ";
let mut matcher = builder.build(text);
// no crop should return complete text with highlighted matches.
- assert_eq!(&matcher.format(format_options), "Ŵôřlḑ");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"Ŵôřlḑ"
+ );
// Text containing unicode match.
let text = "Westfália";
let mut matcher = builder.build(text);
// no crop should return complete text with highlighted matches.
- assert_eq!(&matcher.format(format_options), "Westfália");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"Westfália"
+ );
}
#[test]
@@ -628,83 +640,89 @@ mod tests {
// empty text.
let text = "";
let mut matcher = builder.build(text);
- assert_eq!(&matcher.format(format_options), "");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @""
+ );
// text containing only separators.
let text = ":-)";
let mut matcher = builder.build(text);
- assert_eq!(&matcher.format(format_options), ":-)");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @":-)"
+ );
// Text without any match.
let text = "A quick brown fox can not jump 32 feet, right? Brr, it is cold!";
let mut matcher = builder.build(text);
// no highlight should return 10 first words with a marker at the end.
- assert_eq!(
- &matcher.format(format_options),
- "A quick brown fox can not jump 32 feet, right…"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"A quick brown fox can not jump 32 feet, right…"
);
// Text without any match starting by a separator.
let text = "(A quick brown fox can not jump 32 feet, right? Brr, it is cold!)";
let mut matcher = builder.build(text);
// no highlight should return 10 first words with a marker at the end.
- assert_eq!(
- &matcher.format(format_options),
- "(A quick brown fox can not jump 32 feet, right…"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"(A quick brown fox can not jump 32 feet, right…"
);
// Test phrase propagation
let text = "Natalie risk her future. Split The World is a book written by Emily Henry. I never read it.";
let mut matcher = builder.build(text);
// should crop the phrase instead of croping around the match.
- assert_eq!(
- &matcher.format(format_options),
- "… Split The World is a book written by Emily Henry…",
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"… Split The World is a book written by Emily Henry…"
);
// Text containing some matches.
let text = "Natalie risk her future to build a world with the boy she loves.";
let mut matcher = builder.build(text);
// no highlight should return 10 last words with a marker at the start.
- assert_eq!(
- &matcher.format(format_options),
- "…future to build a world with the boy she loves…"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…future to build a world with the boy she loves…"
);
// Text containing all matches.
let text = "Natalie risk her future to build a world with the boy she loves. Emily Henry: The Love That Split The World.";
let mut matcher = builder.build(text);
// no highlight should return 10 last words with a marker at the start.
- assert_eq!(
- &matcher.format(format_options),
- "…she loves. Emily Henry: The Love That Split The World."
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…she loves. Emily Henry: The Love That Split The World."
);
// Text containing a match unordered and a match ordered.
let text = "The world split void void void void void void void void void split the world void void";
let mut matcher = builder.build(text);
// crop should return 10 last words with a marker at the start.
- assert_eq!(
- &matcher.format(format_options),
- "…void void void void void split the world void void"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…void void void void void split the world void void"
);
// Text containing matches with diferent density.
let text = "split void the void void world void void void void void void void void void void split the world void void";
let mut matcher = builder.build(text);
// crop should return 10 last words with a marker at the start.
- assert_eq!(
- &matcher.format(format_options),
- "…void void void void void split the world void void"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…void void void void void split the world void void"
);
// Text containing matches with same word.
let text = "split split split split split split void void void void void void void void void void split the world void void";
let mut matcher = builder.build(text);
// crop should return 10 last words with a marker at the start.
- assert_eq!(
- &matcher.format(format_options),
- "…void void void void void split the world void void"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…void void void void void split the world void void"
);
}
@@ -719,44 +737,53 @@ mod tests {
// empty text.
let text = "";
let mut matcher = builder.build(text);
- assert_eq!(&matcher.format(format_options), "");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @""
+ );
// text containing only separators.
let text = ":-)";
let mut matcher = builder.build(text);
- assert_eq!(&matcher.format(format_options), ":-)");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @":-)"
+ );
// Text without any match.
let text = "A quick brown fox can not jump 32 feet, right? Brr, it is cold!";
let mut matcher = builder.build(text);
// both should return 10 first words with a marker at the end.
- assert_eq!(
- &matcher.format(format_options),
- "A quick brown fox can not jump 32 feet, right…"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"A quick brown fox can not jump 32 feet, right…"
);
// Text containing some matches.
let text = "Natalie risk her future to build a world with the boy she loves.";
let mut matcher = builder.build(text);
// both should return 10 last words with a marker at the start and highlighted matches.
- assert_eq!(
- &matcher.format(format_options),
- "…future to build a world with the boy she loves…"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…future to build a world with the boy she loves…"
);
// Text containing all matches.
let text = "Natalie risk her future to build a world with the boy she loves. Emily Henry: The Love That Split The World.";
let mut matcher = builder.build(text);
// both should return 10 last words with a marker at the start and highlighted matches.
- assert_eq!(&matcher.format(format_options), "…she loves. Emily Henry: The Love That Split The World.");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…she loves. Emily Henry: The Love That Split The World."
+ );
// Text containing a match unordered and a match ordered.
let text = "The world split void void void void void void void void void split the world void void";
let mut matcher = builder.build(text);
// crop should return 10 last words with a marker at the start.
- assert_eq!(
- &matcher.format(format_options),
- "…void void void void void split the world void void"
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…void void void void void split the world void void"
);
}
@@ -773,19 +800,28 @@ mod tests {
let format_options = FormatOptions { highlight: false, crop: Some(2) };
let mut matcher = builder.build(text);
// because crop size < query size, partially format matches.
- assert_eq!(&matcher.format(format_options), "…split the…");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…split the…"
+ );
// set a smaller crop size
let format_options = FormatOptions { highlight: false, crop: Some(1) };
let mut matcher = builder.build(text);
// because crop size < query size, partially format matches.
- assert_eq!(&matcher.format(format_options), "…split…");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"…split…"
+ );
// set crop size to 0
let format_options = FormatOptions { highlight: false, crop: Some(0) };
let mut matcher = builder.build(text);
// because crop size is 0, crop is ignored.
- assert_eq!(&matcher.format(format_options), "void void split the world void void.");
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"void void split the world void void."
+ );
}
#[test]
@@ -820,11 +856,9 @@ mod tests {
let text = "the do or die can't be he do and or isn't he";
let mut matcher = builder.build(text);
- assert_eq!(
- &matcher.format(format_options),
- "_the_ _do_ _or_ die can't be he _do_ and or isn'_t_ _he_",
- "matches: {:?}",
- &matcher.matches
+ insta::assert_snapshot!(
+ matcher.format(format_options),
+ @"_the_ _do_ _or_ die can't be he _do_ and or isn'_t_ _he_"
);
}
}