make tests windows compatible
This commit is contained in:
parent
05ec8ae92e
commit
0bebd9e07f
|
@ -1,5 +1,3 @@
|
|||
title = "mdBook Documentation"
|
||||
description = "Create books from markdown files. Like Gitbook but implemented in Rust."
|
||||
|
||||
[[authors]]
|
||||
name = "Mathieu David"
|
||||
author = "Mathieu David"
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
title = "An Empty Canvas"
|
||||
title = "The Title"
|
||||
author = "The Author"
|
||||
|
|
|
@ -38,7 +38,22 @@ fn it_renders_multilanguage_book() {
|
|||
assert!(s.contains("<html lang=\"en\">"));
|
||||
assert!(s.contains("<h1>The Pool of Tears</h1>"));
|
||||
assert!(s.contains("<base href=\"../\">"));
|
||||
assert!(s.contains("li><a href=\"en/tears.html\" class=\"active\"><strong>2.</strong> The Pool of Tears</a></li>"));
|
||||
|
||||
let does_it_contain = |check_str: &str, fmt_str: &str, path_parts: Vec<&str>| -> bool {
|
||||
let mut p = PathBuf::from("");
|
||||
for i in path_parts.iter() {
|
||||
p = p.join(i);
|
||||
}
|
||||
let ps = p.to_str().unwrap();
|
||||
// Handmade formatting with replace. For anything more, it'll need Handlebars.
|
||||
let text = fmt_str.replace("{}", ps);
|
||||
check_str.contains(&text)
|
||||
};
|
||||
|
||||
assert!(does_it_contain(
|
||||
&s, "<li><a href=\"{}\" class=\"active\"><strong>2.</strong> The Pool of Tears</a></li>",
|
||||
vec!["en", "tears.html"]
|
||||
));
|
||||
|
||||
book_path = proj.translations.get("fr").unwrap().config.get_dest();
|
||||
chapter_path = book_path.join("tears.html");
|
||||
|
@ -63,9 +78,10 @@ fn it_renders_multilanguage_book() {
|
|||
book_path = proj.translations.get("hu").unwrap().config.get_dest();
|
||||
chapter_path = book_path.join("tarka-farka.html");
|
||||
s = utils::fs::file_to_string(&chapter_path).unwrap();
|
||||
assert!(s.contains("<a href=\"en/index.html\">en</a>"));
|
||||
assert!(s.contains("<a href=\"hu/index.html\">hu</a>"));
|
||||
assert!(s.contains("<a href=\"fr/index.html\">fr</a>"));
|
||||
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">en</a>", vec!["en", "index.html"]));
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">hu</a>", vec!["hu", "index.html"]));
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">fr</a>", vec!["fr", "index.html"]));
|
||||
|
||||
// Test if translation links are found
|
||||
|
||||
|
@ -73,21 +89,24 @@ fn it_renders_multilanguage_book() {
|
|||
|
||||
chapter_path = book_path.join("rabbit-hole.html");
|
||||
s = utils::fs::file_to_string(&chapter_path).unwrap();
|
||||
assert!(s.contains("<a href=\"en/rabbit-hole.html\">en</a>"));
|
||||
assert!(s.contains("<a href=\"hu/nyuszi.html\">hu</a>"));
|
||||
assert!(s.contains("<a href=\"fr/terrier.html\">fr</a>"));
|
||||
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">en</a>", vec!["en", "rabbit-hole.html"]));
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">hu</a>", vec!["hu", "nyuszi.html"]));
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">fr</a>", vec!["fr", "terrier.html"]));
|
||||
|
||||
chapter_path = book_path.join("tears.html");
|
||||
s = utils::fs::file_to_string(&chapter_path).unwrap();
|
||||
assert!(s.contains("<a href=\"en/tears.html\">en</a>"));
|
||||
assert!(s.contains("<a href=\"fr/tears.html\">fr</a>"));
|
||||
assert!(s.contains("<a href=\"hu/tears.html\">hu</a>"));
|
||||
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">en</a>", vec!["en", "tears.html"]));
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">fr</a>", vec!["fr", "tears.html"]));
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">hu</a>", vec!["hu", "tears.html"]));
|
||||
|
||||
chapter_path = book_path.join("long-tale.html");
|
||||
s = utils::fs::file_to_string(&chapter_path).unwrap();
|
||||
assert!(s.contains("<a href=\"en/long-tale.html\">en</a>"));
|
||||
assert!(s.contains("<a href=\"fr/cocasse.html\">fr</a>"));
|
||||
assert!(s.contains("<a href=\"hu/tarka-farka.html\">hu</a>"));
|
||||
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">en</a>", vec!["en", "long-tale.html"]));
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">fr</a>", vec!["fr", "cocasse.html"]));
|
||||
assert!(does_it_contain(&s, "<a href=\"{}\">hu</a>", vec!["hu", "tarka-farka.html"]));
|
||||
|
||||
// Test if print.html is produced for each translations
|
||||
|
||||
|
|
|
@ -54,14 +54,11 @@ fn it_copies_local_assets_when_found() {
|
|||
let path = PathBuf::from(".").join("src").join("tests").join("book-minimal-with-assets");
|
||||
|
||||
let renderer = HtmlHandlebars::new();
|
||||
if let Err(e) = renderer.build(&path, &None) {
|
||||
println!("{:#?}", e);
|
||||
}
|
||||
|
||||
let mut proj = MDBook::new(&path);
|
||||
proj.read_config();
|
||||
proj.parse_books();
|
||||
|
||||
let proj = match renderer.build(&path, &None) {
|
||||
Ok(x) => x,
|
||||
Err(e) => { panic!("{:#?}", e); },
|
||||
};
|
||||
|
||||
let book_path: &Path = proj.translations.get("en").unwrap().config.get_dest();
|
||||
|
||||
|
@ -72,6 +69,8 @@ fn it_copies_local_assets_when_found() {
|
|||
assert!(s.contains("The Library of Babel"));
|
||||
|
||||
assert_eq!(book_path.join("css").join("book.css").exists(), true);
|
||||
assert_eq!(book_path.join("css").join("highlight.css").exists(), false);
|
||||
|
||||
// we left this out from the local assets for testing
|
||||
assert_eq!(book_path.join("css").join("font-awesome.min.css").exists(), false);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#![cfg(test)]
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use book::toc::TocItem;
|
||||
use parse::summary::parse_level;
|
||||
|
||||
#[test]
|
||||
|
@ -29,494 +32,36 @@ fn it_parses_summary_to_tocitems() {
|
|||
[Contributors](misc/contributors.md)
|
||||
"#;
|
||||
|
||||
let result = parse_level(&mut text.split('\n').collect(), 0, vec![0], true).unwrap();
|
||||
let result: Vec<TocItem> = parse_level(&mut text.split('\n').collect(), 0, vec![0], true).unwrap();
|
||||
|
||||
let expected = r#"[
|
||||
Unnumbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Introduction",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"misc/introduction.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"index.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: None
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "mdBook",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"README.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"README.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
1
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Command Line Tool",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"cli/cli-tool.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"cli/cli-tool.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: Some(
|
||||
[
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "init",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"cli/init.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"cli/init.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
2,
|
||||
1
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "build",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"cli/build.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"cli/build.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
2,
|
||||
2
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "watch",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"cli/watch.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"cli/watch.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
2,
|
||||
3
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "serve",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"cli/serve.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"cli/serve.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
2,
|
||||
4
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "test",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"cli/test.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"cli/test.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
2,
|
||||
5
|
||||
]
|
||||
)
|
||||
}
|
||||
)
|
||||
]
|
||||
),
|
||||
section: Some(
|
||||
[
|
||||
2
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Format",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"format/format.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"format/format.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: Some(
|
||||
[
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "SUMMARY.md",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"format/summary.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"format/summary.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
3,
|
||||
1
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Configuration",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"format/config.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"format/config.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
3,
|
||||
2
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Theme",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"format/theme/theme.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"format/theme/theme.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: Some(
|
||||
[
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "index.hbs",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"format/theme/index-hbs.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"format/theme/index-hbs.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
3,
|
||||
3,
|
||||
1
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Syntax highlighting",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"format/theme/syntax-highlighting.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"format/theme/syntax-highlighting.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
3,
|
||||
3,
|
||||
2
|
||||
]
|
||||
)
|
||||
}
|
||||
)
|
||||
]
|
||||
),
|
||||
section: Some(
|
||||
[
|
||||
3,
|
||||
3
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "MathJax Support",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"format/mathjax.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"format/mathjax.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
3,
|
||||
4
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Rust code specific features",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"format/rust.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"format/rust.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
3,
|
||||
5
|
||||
]
|
||||
)
|
||||
}
|
||||
)
|
||||
]
|
||||
),
|
||||
section: Some(
|
||||
[
|
||||
3
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Numbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Rust Library",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"lib/lib.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"lib/lib.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: Some(
|
||||
[
|
||||
4
|
||||
]
|
||||
)
|
||||
}
|
||||
),
|
||||
Spacer,
|
||||
Unnumbered(
|
||||
TocContent {
|
||||
chapter: Chapter {
|
||||
title: "Contributors",
|
||||
content: None,
|
||||
src_path: Some(
|
||||
"misc/contributors.md"
|
||||
),
|
||||
dest_path: Some(
|
||||
"misc/contributors.html"
|
||||
),
|
||||
translation_links: None,
|
||||
translation_id: None,
|
||||
authors: None,
|
||||
translators: None,
|
||||
description: None,
|
||||
css_class: None
|
||||
},
|
||||
sub_items: None,
|
||||
section: None
|
||||
}
|
||||
)
|
||||
]"#;
|
||||
assert_eq!(result.iter().count(), 7);
|
||||
|
||||
assert_eq!(expected, format!("{:#?}", result));
|
||||
{
|
||||
let a = match result[0].clone() {
|
||||
TocItem::Unnumbered(x) => x,
|
||||
_ => { panic!("{:#?}", result[0]); },
|
||||
};
|
||||
|
||||
assert_eq!(a.chapter.title, "Introduction".to_string());
|
||||
assert_eq!(a.chapter.get_src_path().unwrap().as_os_str(),
|
||||
PathBuf::from("misc").join("introduction.md").as_os_str());
|
||||
}
|
||||
|
||||
{
|
||||
let a = match result[2].clone() {
|
||||
TocItem::Numbered(x) => x,
|
||||
_ => { panic!("{:#?}", result[0]); },
|
||||
};
|
||||
|
||||
assert_eq!(a.chapter.title, "Command Line Tool".to_string());
|
||||
assert_eq!(a.chapter.get_src_path().unwrap().as_os_str(),
|
||||
PathBuf::from("cli").join("cli-tool.md").as_os_str());
|
||||
|
||||
let b = match a.sub_items {
|
||||
Some(x) => x,
|
||||
None => { panic!("No sub items! {:#?}", a); }
|
||||
};
|
||||
|
||||
assert_eq!(b.iter().count(), 5);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue