Skip to content

Commit 6746df7

Browse files
committed
Add tests for preprocessor/output default sort order
1 parent a0a01ec commit 6746df7

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

crates/mdbook-driver/src/mdbook/tests.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ fn config_defaults_to_link_and_index_preprocessor_if_not_set() {
4747
// make sure we haven't got anything in the `preprocessor` table
4848
assert!(cfg.preprocessors::<toml::Value>().unwrap().is_empty());
4949

50-
let got = determine_preprocessors(&cfg, Path::new(""));
50+
let got = determine_preprocessors(&cfg, Path::new("")).unwrap();
5151

52-
assert!(got.is_ok());
53-
assert_eq!(got.as_ref().unwrap().len(), 2);
54-
assert_eq!(got.as_ref().unwrap()[0].name(), "index");
55-
assert_eq!(got.as_ref().unwrap()[1].name(), "links");
52+
let names: Vec<_> = got.values().map(|p| p.name()).collect();
53+
assert_eq!(names, ["index", "links"]);
5654
}
5755

5856
#[test]
@@ -252,3 +250,35 @@ fn preprocessor_should_run_falls_back_to_supports_renderer_method() {
252250
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg).unwrap();
253251
assert_eq!(got, should_be);
254252
}
253+
254+
// Default is to sort preprocessors alphabetically.
255+
#[test]
256+
fn preprocessor_sorted_by_name() {
257+
let cfg_str = r#"
258+
[preprocessor.xyz]
259+
[preprocessor.abc]
260+
"#;
261+
262+
let cfg = Config::from_str(cfg_str).unwrap();
263+
264+
let got = determine_preprocessors(&cfg, Path::new("")).unwrap();
265+
266+
let names: Vec<_> = got.values().map(|p| p.name()).collect();
267+
assert_eq!(names, ["abc", "index", "links", "xyz"]);
268+
}
269+
270+
// Default is to sort renderers alphabetically.
271+
#[test]
272+
fn renderers_sorted_by_name() {
273+
let cfg_str = r#"
274+
[output.xyz]
275+
[output.abc]
276+
"#;
277+
278+
let cfg = Config::from_str(cfg_str).unwrap();
279+
280+
let got = determine_renderers(&cfg).unwrap();
281+
282+
let names: Vec<_> = got.values().map(|p| p.name()).collect();
283+
assert_eq!(names, ["abc", "xyz"]);
284+
}

0 commit comments

Comments
 (0)