Skip to content

Commit d928952

Browse files
committed
rustdoc: Write crate name
1 parent ae58426 commit d928952

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/rustdoc/gen.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ type ctxt = {
33
w: io::writer
44
};
55

6+
fn write_markdown(
7+
doc: doc::cratedoc,
8+
_crate: @ast::crate,
9+
writer: io::writer
10+
) {
11+
let ctxt = {
12+
ps: pprust::rust_printer(writer),
13+
w: writer
14+
};
15+
16+
write_header(ctxt, doc.topmod.name);
17+
}
18+
619
#[doc(
720
brief = "Generate a crate document header.",
821
args(rd = "Rustdoc context",
@@ -46,3 +59,25 @@ fn write_fndoc(ctxt: ctxt, ident: str, doc: doc::fndoc, decl: ast::fn_decl) {
4659
none. { }
4760
}
4861
}
62+
63+
#[cfg(test)]
64+
mod tests {
65+
fn write_markdown_str(
66+
doc: doc::cratedoc,
67+
crate: @ast::crate
68+
) -> str {
69+
let buffer = io::mk_mem_buffer();
70+
let writer = io::mem_buffer_writer(buffer);
71+
write_markdown(doc, crate, writer);
72+
ret io::mem_buffer_str(buffer);
73+
}
74+
75+
#[test]
76+
fn write_markdown_should_write_crate_header() {
77+
let source = "";
78+
let ast = parse::from_str(source);
79+
let doc = extract::extract(ast, "belch");
80+
let markdown = write_markdown_str(doc, ast);
81+
assert str::contains(markdown, "# Crate belch\n");
82+
}
83+
}

0 commit comments

Comments
 (0)