mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-27 07:14:26 +01:00
chore: Rewrite tests to use iterators and be easily testable
This commit is contained in:
parent
5aa49d232c
commit
9cc154da05
@ -581,10 +581,9 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
|
|
||||||
@ -593,10 +592,9 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
}
|
}
|
||||||
@ -615,10 +613,9 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
|
|
||||||
@ -627,10 +624,9 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
|
|
||||||
@ -660,10 +656,9 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
|
|
||||||
@ -672,10 +667,9 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
}
|
}
|
||||||
@ -697,22 +691,19 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 3, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 3);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(2), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(2), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 5, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 5);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
|
|
||||||
@ -721,22 +712,19 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 3, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 3);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(2), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(2), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 5, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 5);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
|
|
||||||
@ -745,22 +733,19 @@ mod tests {
|
|||||||
let mut iter = results.into_iter();
|
let mut iter = results.into_iter();
|
||||||
|
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 0, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 0);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 3, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 3);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), Some(Document { id: DocumentId(2), matches }) => {
|
assert_matches!(iter.next(), Some(Document { id: DocumentId(2), matches }) => {
|
||||||
assert_eq!(matches.len(), 1);
|
let mut matches = matches.into_iter();
|
||||||
let match_ = matches[0];
|
assert_matches!(matches.next(), Some(Match { query_index: 0, word_index: 5, .. }));
|
||||||
assert_eq!(match_.query_index, 0);
|
assert_matches!(matches.next(), None);
|
||||||
assert_eq!(match_.word_index, 5);
|
|
||||||
});
|
});
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user