rustdoc: Extract boilerplate from gen tests
This commit is contained in:
parent
0142e807dd
commit
c17d58d5ba
|
@ -131,6 +131,13 @@ fn write_fn(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
fn render(source: str) -> str {
|
||||||
|
let srv = astsrv::mk_srv_from_str(source);
|
||||||
|
let doc = extract::from_srv(srv, "");
|
||||||
|
let doc = attr_pass::mk_pass()(srv, doc);
|
||||||
|
write_markdown_str(doc)
|
||||||
|
}
|
||||||
|
|
||||||
fn write_markdown_str(
|
fn write_markdown_str(
|
||||||
doc: doc::cratedoc
|
doc: doc::cratedoc
|
||||||
) -> str {
|
) -> str {
|
||||||
|
@ -142,57 +149,40 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn write_markdown_should_write_crate_header() {
|
fn write_markdown_should_write_crate_header() {
|
||||||
let source = "";
|
let srv = astsrv::mk_srv_from_str("");
|
||||||
let ast = parse::from_str(source);
|
let doc = extract::from_srv(srv, "belch");
|
||||||
let doc = extract::extract(ast, "belch");
|
let doc = attr_pass::mk_pass()(srv, doc);
|
||||||
let markdown = write_markdown_str(doc);
|
let markdown = write_markdown_str(doc);
|
||||||
assert str::contains(markdown, "# Crate belch");
|
assert str::contains(markdown, "# Crate belch");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn write_markdown_should_write_function_header() {
|
fn write_markdown_should_write_function_header() {
|
||||||
let source = "fn func() { }";
|
let markdown = render("fn func() { }");
|
||||||
let ast = parse::from_str(source);
|
|
||||||
let doc = extract::extract(ast, "");
|
|
||||||
let markdown = write_markdown_str(doc);
|
|
||||||
assert str::contains(markdown, "## Function `func`");
|
assert str::contains(markdown, "## Function `func`");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn write_markdown_should_write_mod_headers() {
|
fn write_markdown_should_write_mod_headers() {
|
||||||
let source = "mod moo { }";
|
let markdown = render("mod moo { }");
|
||||||
let ast = parse::from_str(source);
|
|
||||||
let doc = extract::extract(ast, "");
|
|
||||||
let markdown = write_markdown_str(doc);
|
|
||||||
assert str::contains(markdown, "## Module `moo`");
|
assert str::contains(markdown, "## Module `moo`");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_leave_blank_line_after_header() {
|
fn should_leave_blank_line_after_header() {
|
||||||
let source = "mod morp { }";
|
let markdown = render("mod morp { }");
|
||||||
let ast = parse::from_str(source);
|
|
||||||
let doc = extract::extract(ast, "");
|
|
||||||
let markdown = write_markdown_str(doc);
|
|
||||||
assert str::contains(markdown, "Module `morp`\n\n");
|
assert str::contains(markdown, "Module `morp`\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_leave_blank_line_between_fn_header_and_brief() {
|
fn should_leave_blank_line_between_fn_header_and_brief() {
|
||||||
let source = "#[doc(brief = \"brief\")] fn a() { }";
|
let markdown = render("#[doc(brief = \"brief\")] fn a() { }");
|
||||||
let srv = astsrv::mk_srv_from_str(source);
|
|
||||||
let doc = extract::from_srv(srv, "");
|
|
||||||
let doc = attr_pass::mk_pass()(srv, doc);
|
|
||||||
let markdown = write_markdown_str(doc);
|
|
||||||
assert str::contains(markdown, "Function `a`\n\nbrief");
|
assert str::contains(markdown, "Function `a`\n\nbrief");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_leve_blank_line_after_brief() {
|
fn should_leve_blank_line_after_brief() {
|
||||||
let source = "#[doc(brief = \"brief\")] fn a() { }";
|
let markdown = render("#[doc(brief = \"brief\")] fn a() { }");
|
||||||
let srv = astsrv::mk_srv_from_str(source);
|
|
||||||
let doc = extract::from_srv(srv, "");
|
|
||||||
let doc = attr_pass::mk_pass()(srv, doc);
|
|
||||||
let markdown = write_markdown_str(doc);
|
|
||||||
assert str::contains(markdown, "brief\n\n");
|
assert str::contains(markdown, "brief\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue