Skip to content

Commit 4700cd0

Browse files
committed
---
yaml --- r: 11736 b: refs/heads/master c: e399263 h: refs/heads/master v: v3
1 parent 2d25c54 commit 4700cd0

File tree

2 files changed

+94
-61
lines changed

2 files changed

+94
-61
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0ad8265fee1af5551a0d9ca284788ee1a2116fa5
2+
refs/heads/master: e399263b5e9d726c0c1082d2092527067b9aadfe
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustdoc/markdown_pass.rs

Lines changed: 93 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ fn should_request_new_writer_for_each_page() {
120120
enum hlvl {
121121
h1 = 1,
122122
h2 = 2,
123-
h3 = 3
123+
h3 = 3,
124+
h4 = 4
124125
}
125126

126127
fn write_header(ctxt: ctxt, lvl: hlvl, doc: doc::itemtag) {
@@ -238,12 +239,84 @@ fn should_write_full_path_to_mod() {
238239
assert str::contains(markdown, "# Module `a::b::c`");
239240
}
240241

242+
fn write_common(
243+
ctxt: ctxt,
244+
brief: option<str>,
245+
desc: option<str>,
246+
sections: [doc::section]
247+
) {
248+
write_brief(ctxt, brief);
249+
write_desc(ctxt, desc);
250+
write_sections(ctxt, sections);
251+
}
252+
253+
fn write_brief(
254+
ctxt: ctxt,
255+
brief: option<str>
256+
) {
257+
alt brief {
258+
some(brief) {
259+
ctxt.w.write_line(brief);
260+
ctxt.w.write_line("");
261+
}
262+
none { }
263+
}
264+
}
265+
266+
#[test]
267+
fn should_leave_blank_line_after_brief() {
268+
let markdown = test::render("#[doc(brief = \"brief\")] fn a() { }");
269+
assert str::contains(markdown, "brief\n\n");
270+
}
271+
272+
#[test]
273+
fn should_leave_blank_line_between_brief_and_desc() {
274+
let markdown = test::render(
275+
"#[doc(brief = \"brief\", desc = \"desc\")] fn a() { }"
276+
);
277+
assert str::contains(markdown, "brief\n\ndesc");
278+
}
279+
280+
fn write_desc(
281+
ctxt: ctxt,
282+
desc: option<str>
283+
) {
284+
alt desc {
285+
some(desc) {
286+
ctxt.w.write_line(desc);
287+
ctxt.w.write_line("");
288+
}
289+
none { }
290+
}
291+
}
292+
293+
fn write_sections(ctxt: ctxt, sections: [doc::section]) {
294+
vec::iter(sections) {|section|
295+
write_section(ctxt, section);
296+
}
297+
}
298+
299+
fn write_section(ctxt: ctxt, section: doc::section) {
300+
write_header_(ctxt, h4, section.header);
301+
ctxt.w.write_line(section.body);
302+
ctxt.w.write_line("");
303+
}
304+
305+
#[test]
306+
fn should_write_sections() {
307+
let markdown = test::render(
308+
"#[doc = \"\
309+
# Header\n\
310+
Body\"]\
311+
mod a { }");
312+
assert str::contains(markdown, "#### Header\n\nBody\n\n");
313+
}
314+
241315
fn write_mod_contents(
242316
ctxt: ctxt,
243317
doc: doc::moddoc
244318
) {
245-
write_brief(ctxt, doc.brief());
246-
write_desc(ctxt, doc.desc());
319+
write_common(ctxt, doc.brief(), doc.desc(), doc.sections());
247320
if option::is_some(doc.index) {
248321
write_index(ctxt, option::get(doc.index));
249322
}
@@ -321,9 +394,7 @@ fn should_not_write_index_if_no_entries() {
321394

322395
fn write_nmod(ctxt: ctxt, doc: doc::nmoddoc) {
323396
write_header(ctxt, h1, doc::nmodtag(doc));
324-
325-
write_brief(ctxt, doc.brief());
326-
write_desc(ctxt, doc.desc());
397+
write_common(ctxt, doc.brief(), doc.desc(), doc.sections());
327398

328399
for fndoc in doc.fns {
329400
write_fn(ctxt, fndoc);
@@ -353,6 +424,7 @@ fn write_fn(
353424
doc.sig,
354425
doc.brief(),
355426
doc.desc(),
427+
doc.sections(),
356428
doc.args,
357429
doc.return,
358430
doc.failure
@@ -364,13 +436,13 @@ fn write_fnlike(
364436
sig: option<str>,
365437
brief: option<str>,
366438
desc: option<str>,
439+
sections: [doc::section],
367440
args: [doc::argdoc],
368441
return: doc::retdoc,
369442
failure: option<str>
370443
) {
371444
write_sig(ctxt, sig);
372-
write_brief(ctxt, brief);
373-
write_desc(ctxt, desc);
445+
write_common(ctxt, brief, desc, sections);
374446
write_args(ctxt, args);
375447
write_return(ctxt, return);
376448
write_failure(ctxt, failure);
@@ -437,46 +509,6 @@ fn should_leave_blank_line_between_fn_header_and_sig() {
437509
assert str::contains(markdown, "Function `a`\n\n fn a()");
438510
}
439511

440-
fn write_brief(
441-
ctxt: ctxt,
442-
brief: option<str>
443-
) {
444-
alt brief {
445-
some(brief) {
446-
ctxt.w.write_line(brief);
447-
ctxt.w.write_line("");
448-
}
449-
none { }
450-
}
451-
}
452-
453-
#[test]
454-
fn should_leave_blank_line_after_brief() {
455-
let markdown = test::render("#[doc(brief = \"brief\")] fn a() { }");
456-
assert str::contains(markdown, "brief\n\n");
457-
}
458-
459-
#[test]
460-
fn should_leave_blank_line_between_brief_and_desc() {
461-
let markdown = test::render(
462-
"#[doc(brief = \"brief\", desc = \"desc\")] fn a() { }"
463-
);
464-
assert str::contains(markdown, "brief\n\ndesc");
465-
}
466-
467-
fn write_desc(
468-
ctxt: ctxt,
469-
desc: option<str>
470-
) {
471-
alt desc {
472-
some(desc) {
473-
ctxt.w.write_line(desc);
474-
ctxt.w.write_line("");
475-
}
476-
none { }
477-
}
478-
}
479-
480512
fn write_args(
481513
ctxt: ctxt,
482514
args: [doc::argdoc]
@@ -602,8 +634,7 @@ fn write_const(
602634
) {
603635
write_header(ctxt, h2, doc::consttag(doc));
604636
write_sig(ctxt, doc.ty);
605-
write_brief(ctxt, doc.brief());
606-
write_desc(ctxt, doc.desc());
637+
write_common(ctxt, doc.brief(), doc.desc(), doc.sections());
607638
}
608639

609640
#[test]
@@ -625,8 +656,7 @@ fn write_enum(
625656
doc: doc::enumdoc
626657
) {
627658
write_header(ctxt, h2, doc::enumtag(doc));
628-
write_brief(ctxt, doc.brief());
629-
write_desc(ctxt, doc.desc());
659+
write_common(ctxt, doc.brief(), doc.desc(), doc.sections());
630660
write_variants(ctxt, doc.variants);
631661
}
632662

@@ -708,8 +738,7 @@ fn should_write_variant_list_with_signatures() {
708738
fn write_res(ctxt: ctxt, doc: doc::resdoc) {
709739
write_header(ctxt, h2, doc::restag(doc));
710740
write_sig(ctxt, doc.sig);
711-
write_brief(ctxt, doc.brief());
712-
write_desc(ctxt, doc.desc());
741+
write_common(ctxt, doc.brief(), doc.desc(), doc.sections());
713742
write_args(ctxt, doc.args);
714743
}
715744

@@ -734,8 +763,7 @@ fn should_write_resource_args() {
734763

735764
fn write_iface(ctxt: ctxt, doc: doc::ifacedoc) {
736765
write_header(ctxt, h2, doc::ifacetag(doc));
737-
write_brief(ctxt, doc.brief());
738-
write_desc(ctxt, doc.desc());
766+
write_common(ctxt, doc.brief(), doc.desc(), doc.sections());
739767
write_methods(ctxt, doc.methods);
740768
}
741769

@@ -750,6 +778,7 @@ fn write_method(ctxt: ctxt, doc: doc::methoddoc) {
750778
doc.sig,
751779
doc.brief,
752780
doc.desc,
781+
doc.sections,
753782
doc.args,
754783
doc.return,
755784
doc.failure
@@ -827,8 +856,7 @@ fn should_write_iface_method_failure_conditions() {
827856

828857
fn write_impl(ctxt: ctxt, doc: doc::impldoc) {
829858
write_header(ctxt, h2, doc::impltag(doc));
830-
write_brief(ctxt, doc.brief());
831-
write_desc(ctxt, doc.desc());
859+
write_common(ctxt, doc.brief(), doc.desc(), doc.sections());
832860
write_methods(ctxt, doc.methods);
833861
}
834862

@@ -913,8 +941,7 @@ fn write_type(
913941
) {
914942
write_header(ctxt, h2, doc::tytag(doc));
915943
write_sig(ctxt, doc.sig);
916-
write_brief(ctxt, doc.brief());
917-
write_desc(ctxt, doc.desc());
944+
write_common(ctxt, doc.brief(), doc.desc(), doc.sections());
918945
}
919946

920947
#[test]
@@ -968,6 +995,12 @@ mod test {
968995
#debug("doc (path): %?", doc);
969996
let doc = attr_pass::mk_pass().f(srv, doc);
970997
#debug("doc (attr): %?", doc);
998+
let doc = unindent_pass::mk_pass().f(srv, doc);
999+
#debug("doc (unindent): %?", doc);
1000+
let doc = sectionalize_pass::mk_pass().f(srv, doc);
1001+
#debug("doc (trim): %?", doc);
1002+
let doc = trim_pass::mk_pass().f(srv, doc);
1003+
#debug("doc (sectionalize): %?", doc);
9711004
let doc = markdown_index_pass::mk_pass(config).f(srv, doc);
9721005
#debug("doc (index): %?", doc);
9731006
(srv, doc)

0 commit comments

Comments
 (0)