@@ -447,3 +447,134 @@ fn main() {}"
447447 let ( output, len) = make_test ( input, None , false , & opts, None ) ;
448448 assert_eq ! ( ( output, len) , ( expected, 1 ) ) ;
449449}
450+
451+ #[ test]
452+ fn comments ( ) {
453+ let opts = default_global_opts ( "" ) ;
454+ let input = r##"
455+ //! A doc comment that applies to the implicit anonymous module of this crate
456+
457+ pub mod outer_module {
458+
459+ //! - Inner line doc
460+ //!! - Still an inner line doc (but with a bang at the beginning)
461+
462+ /*! - Inner block doc */
463+ /*!! - Still an inner block doc (but with a bang at the beginning) */
464+
465+ // - Only a comment
466+ /// - Outer line doc (exactly 3 slashes)
467+ //// - Only a comment
468+
469+ /* - Only a comment */
470+ /** - Outer block doc (exactly) 2 asterisks */
471+ /*** - Only a comment */
472+
473+ pub mod inner_module {}
474+
475+ pub mod nested_comments {
476+ /* In Rust /* we can /* nest comments */ */ */
477+
478+ // All three types of block comments can contain or be nested inside
479+ // any other type:
480+
481+ /* /* */ /** */ /*! */ */
482+ /*! /* */ /** */ /*! */ */
483+ /** /* */ /** */ /*! */ */
484+ pub mod dummy_item {}
485+ }
486+
487+ pub mod degenerate_cases {
488+ // empty inner line doc
489+ //!
490+
491+ // empty inner block doc
492+ /*!*/
493+
494+ // empty line comment
495+ //
496+
497+ // empty outer line doc
498+ ///
499+
500+ // empty block comment
501+ /**/
502+
503+ pub mod dummy_item {}
504+
505+ // empty 2-asterisk block isn't a doc block, it is a block comment
506+ /***/
507+
508+ }
509+
510+ /* The next one isn't allowed because outer doc comments
511+ require an item that will receive the doc */
512+
513+ /// Where is my item?
514+ }
515+ "## ;
516+ let expected = "
517+ //! A doc comment that applies to the implicit anonymous module of this crate
518+
519+ pub mod outer_module {
520+
521+ //! - Inner line doc
522+ //!! - Still an inner line doc (but with a bang at the beginning)
523+
524+ /*! - Inner block doc */
525+ /*!! - Still an inner block doc (but with a bang at the beginning) */
526+
527+ // - Only a comment
528+ /// - Outer line doc (exactly 3 slashes)
529+ //// - Only a comment
530+
531+ /* - Only a comment */
532+ /** - Outer block doc (exactly) 2 asterisks */
533+ /*** - Only a comment */
534+
535+ pub mod inner_module {}
536+
537+ pub mod nested_comments {
538+ /* In Rust /* we can /* nest comments */ */ */
539+
540+ // All three types of block comments can contain or be nested inside
541+ // any other type:
542+
543+ /* /* */ /** */ /*! */ */
544+ /*! /* */ /** */ /*! */ */
545+ /** /* */ /** */ /*! */ */
546+ pub mod dummy_item {}
547+ }
548+
549+ pub mod degenerate_cases {
550+ // empty inner line doc
551+ //!
552+
553+ // empty inner block doc
554+ /*!*/
555+
556+ // empty line comment
557+ //
558+
559+ // empty outer line doc
560+ ///
561+
562+ // empty block comment
563+ /**/
564+
565+ pub mod dummy_item {}
566+
567+ // empty 2-asterisk block isn't a doc block, it is a block comment
568+ /***/
569+
570+ }
571+
572+ /* The next one isn't allowed because outer doc comments
573+ require an item that will receive the doc */
574+
575+ /// Where is my item?
576+ }
577+ " . to_string ( ) ;
578+ let ( output, len) = make_test ( input, None , false , & opts, None ) ;
579+ assert_eq ! ( ( output, len) , ( expected, 0 ) ) ;
580+ }
0 commit comments