@@ -120,7 +120,8 @@ fn should_request_new_writer_for_each_page() {
120
120
enum hlvl {
121
121
h1 = 1 ,
122
122
h2 = 2 ,
123
- h3 = 3
123
+ h3 = 3 ,
124
+ h4 = 4
124
125
}
125
126
126
127
fn write_header ( ctxt : ctxt , lvl : hlvl , doc : doc:: itemtag ) {
@@ -238,12 +239,84 @@ fn should_write_full_path_to_mod() {
238
239
assert str:: contains ( markdown, "# Module `a::b::c`" ) ;
239
240
}
240
241
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 \n desc" ) ;
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 \n Body\n \n " ) ;
313
+ }
314
+
241
315
fn write_mod_contents (
242
316
ctxt : ctxt ,
243
317
doc : doc:: moddoc
244
318
) {
245
- write_brief ( ctxt, doc. brief ( ) ) ;
246
- write_desc ( ctxt, doc. desc ( ) ) ;
319
+ write_common ( ctxt, doc. brief ( ) , doc. desc ( ) , doc. sections ( ) ) ;
247
320
if option:: is_some ( doc. index ) {
248
321
write_index ( ctxt, option:: get ( doc. index ) ) ;
249
322
}
@@ -321,9 +394,7 @@ fn should_not_write_index_if_no_entries() {
321
394
322
395
fn write_nmod ( ctxt : ctxt , doc : doc:: nmoddoc ) {
323
396
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 ( ) ) ;
327
398
328
399
for fndoc in doc. fns {
329
400
write_fn ( ctxt, fndoc) ;
@@ -353,6 +424,7 @@ fn write_fn(
353
424
doc. sig ,
354
425
doc. brief ( ) ,
355
426
doc. desc ( ) ,
427
+ doc. sections ( ) ,
356
428
doc. args ,
357
429
doc. return ,
358
430
doc. failure
@@ -364,13 +436,13 @@ fn write_fnlike(
364
436
sig : option < str > ,
365
437
brief : option < str > ,
366
438
desc : option < str > ,
439
+ sections : [ doc:: section ] ,
367
440
args : [ doc:: argdoc ] ,
368
441
return : doc:: retdoc ,
369
442
failure : option < str >
370
443
) {
371
444
write_sig ( ctxt, sig) ;
372
- write_brief ( ctxt, brief) ;
373
- write_desc ( ctxt, desc) ;
445
+ write_common ( ctxt, brief, desc, sections) ;
374
446
write_args ( ctxt, args) ;
375
447
write_return ( ctxt, return ) ;
376
448
write_failure ( ctxt, failure) ;
@@ -437,46 +509,6 @@ fn should_leave_blank_line_between_fn_header_and_sig() {
437
509
assert str:: contains ( markdown, "Function `a`\n \n fn a()" ) ;
438
510
}
439
511
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 \n desc" ) ;
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
-
480
512
fn write_args (
481
513
ctxt : ctxt ,
482
514
args : [ doc:: argdoc ]
@@ -602,8 +634,7 @@ fn write_const(
602
634
) {
603
635
write_header ( ctxt, h2, doc:: consttag ( doc) ) ;
604
636
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 ( ) ) ;
607
638
}
608
639
609
640
#[ test]
@@ -625,8 +656,7 @@ fn write_enum(
625
656
doc : doc:: enumdoc
626
657
) {
627
658
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 ( ) ) ;
630
660
write_variants ( ctxt, doc. variants ) ;
631
661
}
632
662
@@ -708,8 +738,7 @@ fn should_write_variant_list_with_signatures() {
708
738
fn write_res ( ctxt : ctxt , doc : doc:: resdoc ) {
709
739
write_header ( ctxt, h2, doc:: restag ( doc) ) ;
710
740
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 ( ) ) ;
713
742
write_args ( ctxt, doc. args ) ;
714
743
}
715
744
@@ -734,8 +763,7 @@ fn should_write_resource_args() {
734
763
735
764
fn write_iface ( ctxt : ctxt , doc : doc:: ifacedoc ) {
736
765
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 ( ) ) ;
739
767
write_methods ( ctxt, doc. methods ) ;
740
768
}
741
769
@@ -750,6 +778,7 @@ fn write_method(ctxt: ctxt, doc: doc::methoddoc) {
750
778
doc. sig ,
751
779
doc. brief ,
752
780
doc. desc ,
781
+ doc. sections ,
753
782
doc. args ,
754
783
doc. return ,
755
784
doc. failure
@@ -827,8 +856,7 @@ fn should_write_iface_method_failure_conditions() {
827
856
828
857
fn write_impl ( ctxt : ctxt , doc : doc:: impldoc ) {
829
858
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 ( ) ) ;
832
860
write_methods ( ctxt, doc. methods ) ;
833
861
}
834
862
@@ -913,8 +941,7 @@ fn write_type(
913
941
) {
914
942
write_header ( ctxt, h2, doc:: tytag ( doc) ) ;
915
943
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 ( ) ) ;
918
945
}
919
946
920
947
#[ test]
@@ -968,6 +995,12 @@ mod test {
968
995
#debug ( "doc (path): %?" , doc) ;
969
996
let doc = attr_pass:: mk_pass ( ) . f ( srv, doc) ;
970
997
#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) ;
971
1004
let doc = markdown_index_pass:: mk_pass ( config) . f ( srv, doc) ;
972
1005
#debug ( "doc (index): %?" , doc) ;
973
1006
( srv, doc)
0 commit comments