@@ -3,10 +3,11 @@ mod dummy_book;
33use crate :: dummy_book:: { assert_contains_strings, assert_doesnt_contain_strings, DummyBook } ;
44
55use anyhow:: Context ;
6+ use mdbook:: book:: Chapter ;
67use mdbook:: config:: Config ;
78use mdbook:: errors:: * ;
89use mdbook:: utils:: fs:: write_file;
9- use mdbook:: MDBook ;
10+ use mdbook:: { BookItem , MDBook } ;
1011use pretty_assertions:: assert_eq;
1112use select:: document:: Document ;
1213use select:: predicate:: { Attr , Class , Name , Predicate } ;
@@ -1031,3 +1032,22 @@ fn custom_header_attributes() {
10311032 ] ;
10321033 assert_contains_strings ( & contents, summary_strings) ;
10331034}
1035+
1036+ #[ test]
1037+ #[ should_panic]
1038+ fn with_no_source_path ( ) {
1039+ // Test for a regression where search would fail if source_path is None.
1040+ let temp = DummyBook :: new ( ) . build ( ) . unwrap ( ) ;
1041+ let mut md = MDBook :: load ( temp. path ( ) ) . unwrap ( ) ;
1042+ let chapter = Chapter {
1043+ name : "Sample chapter" . to_string ( ) ,
1044+ content : "" . to_string ( ) ,
1045+ number : None ,
1046+ sub_items : Vec :: new ( ) ,
1047+ path : Some ( PathBuf :: from ( "sample.html" ) ) ,
1048+ source_path : None ,
1049+ parent_names : Vec :: new ( ) ,
1050+ } ;
1051+ md. book . sections . push ( BookItem :: Chapter ( chapter) ) ;
1052+ md. build ( ) . unwrap ( ) ;
1053+ }
0 commit comments