Add test case for Index::find
As we only support the new search index format introduced in April 2020, the test is only run for Rust >= 1.44.0.
This commit is contained in:
parent
77a9163bb1
commit
c97ac33dc9
@ -20,6 +20,7 @@ SPDX-License-Identifier: MIT
|
||||
- Add tests for Rust 1.46.0.
|
||||
- Improve test suite:
|
||||
- Add test for `Parser::find_member`.
|
||||
- Add test for `Index::find`.
|
||||
|
||||
## v0.2.0 (2020-08-11)
|
||||
|
||||
|
43
src/index.rs
43
src/index.rs
@ -7,7 +7,7 @@
|
||||
//! list of items groupd by their crate.
|
||||
//!
|
||||
//! For details on the format of the search index, see the `html/render.rs` file in `librustdoc`.
|
||||
//! Note that the format of the search index changed in April 2020 with commit
|
||||
//! Note that the format of the search index changed in April 2020 (Rust 1.44.0) with commit
|
||||
//! b4fb3069ce82f61f84a9487d17fb96389d55126a. We only support the new format as the old format is
|
||||
//! much harder to parse.
|
||||
//!
|
||||
@ -215,8 +215,9 @@ impl Index {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{CrateData, Data, ItemData};
|
||||
use super::{CrateData, Data, Index, IndexItem, ItemData};
|
||||
use crate::doc::ItemType;
|
||||
use crate::test_utils::with_rustdoc;
|
||||
|
||||
#[test]
|
||||
fn test_empty() {
|
||||
@ -254,4 +255,42 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_index() {
|
||||
with_rustdoc(">=1.44.0", |_, path| {
|
||||
let index = Index::load(path.join("search-index.js")).unwrap().unwrap();
|
||||
|
||||
let empty: Vec<IndexItem> = Vec::new();
|
||||
|
||||
let node_data_ref = vec![IndexItem {
|
||||
name: "kuchiki::NodeDataRef".to_owned().into(),
|
||||
ty: ItemType::Struct,
|
||||
description: "Holds a strong reference to a node, but dereferences to…".to_owned(),
|
||||
}];
|
||||
assert_eq!(node_data_ref, index.find(&"NodeDataRef".to_owned().into()));
|
||||
assert_eq!(
|
||||
node_data_ref,
|
||||
index.find(&"kuchiki::NodeDataRef".to_owned().into())
|
||||
);
|
||||
assert_eq!(empty, index.find(&"DataRef".to_owned().into()));
|
||||
assert_eq!(empty, index.find(&"NodeDataReff".to_owned().into()));
|
||||
|
||||
let as_node = vec![IndexItem {
|
||||
name: "kuchiki::NodeDataRef::as_node".to_owned().into(),
|
||||
ty: ItemType::Method,
|
||||
description: "Access the corresponding node.".to_owned(),
|
||||
}];
|
||||
assert_eq!(as_node, index.find(&"as_node".to_owned().into()));
|
||||
assert_eq!(
|
||||
as_node,
|
||||
index.find(&"NodeDataRef::as_node".to_owned().into())
|
||||
);
|
||||
assert_eq!(
|
||||
as_node,
|
||||
index.find(&"kuchiki::NodeDataRef::as_node".to_owned().into())
|
||||
);
|
||||
assert_eq!(empty, index.find(&"DataRef::as_node".to_owned().into()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user