diff --git a/src/query/scorer.rs b/src/query/scorer.rs index 2143b4464..e1bba452f 100644 --- a/src/query/scorer.rs +++ b/src/query/scorer.rs @@ -51,7 +51,8 @@ impl DocSet for EmptyScorer { } fn doc(&self) -> DocId { - DocId::max_value() + panic!("You may not call .doc() on a scorer \ + where the last call to advance() did not return true."); } fn size_hint(&self) -> u32 { @@ -122,3 +123,21 @@ impl Scorer for ConstScorer { 1f32 } } + +#[cfg(test)] +mod tests { + use super::EmptyScorer; + use DocSet; + + #[test] + fn test_empty_scorer() { + let mut empty_scorer = EmptyScorer; + assert!(!empty_scorer.advance()); + } + + #[test] + #[should_panic] + fn test_empty_scorer_panic_on_doc_call() { + EmptyScorer.doc(); + } +}