Skip to content

Commit c98cfa4

Browse files
committed
rustdoc: Write markdown for consts
1 parent 74ab606 commit c98cfa4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/rustdoc/gen.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ fn write_mod_contents(
8181
write_brief(ctxt, doc.brief);
8282
write_desc(ctxt, doc.desc);
8383

84+
for constdoc in *doc.consts {
85+
write_const(ctxt, constdoc);
86+
}
87+
8488
for fndoc in *doc.fns {
8589
write_fn(ctxt, fndoc);
8690
}
@@ -300,6 +304,30 @@ fn should_write_return_description_on_same_line_as_type() {
300304
assert str::contains(markdown, "Returns `int` - blorp");
301305
}
302306

307+
fn write_const(
308+
ctxt: ctxt,
309+
doc: doc::constdoc
310+
) {
311+
write_header(ctxt, h3, #fmt("Const `%s`", doc.name));
312+
write_sig(ctxt, doc.ty);
313+
write_brief(ctxt, doc.brief);
314+
write_desc(ctxt, doc.desc);
315+
}
316+
317+
#[test]
318+
fn should_write_const_header() {
319+
let markdown = test::render("const a: bool = true;");
320+
assert str::contains(markdown, "### Const `a`\n\n");
321+
}
322+
323+
#[test]
324+
fn should_write_const_description() {
325+
let markdown = test::render(
326+
"#[doc(brief = \"a\", desc = \"b\")]\
327+
const a: bool = true;");
328+
assert str::contains(markdown, "\n\na\n\nb\n\n");
329+
}
330+
303331
#[cfg(test)]
304332
mod test {
305333
fn render(source: str) -> str {

0 commit comments

Comments
 (0)