about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-03-27 16:23:41 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-03-27 16:23:50 +0100
commit1494da4ffbfab8d0b7a62dd37d9f4a77f1038840 (patch)
treee02771013114ba4d443c86a41f1390baeca6728c
parent2004dacef2fe6e9b75e56db04587579111679b82 (diff)
downloadrust-1494da4ffbfab8d0b7a62dd37d9f4a77f1038840.tar.gz
rust-1494da4ffbfab8d0b7a62dd37d9f4a77f1038840.zip
Add new regression test for doctest
-rw-r--r--src/librustdoc/doctest/tests.rs131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/librustdoc/doctest/tests.rs b/src/librustdoc/doctest/tests.rs
index 4833ea04051..949ed837db3 100644
--- a/src/librustdoc/doctest/tests.rs
+++ b/src/librustdoc/doctest/tests.rs
@@ -447,3 +447,134 @@ fn main() {}"
     let (output, len) = make_test(input, None, false, &opts, None);
     assert_eq!((output, len), (expected, 1));
 }
+
+#[test]
+fn comments() {
+    let opts = default_global_opts("");
+    let input = r##"
+//! A doc comment that applies to the implicit anonymous module of this crate
+
+pub mod outer_module {
+
+    //!  - Inner line doc
+    //!! - Still an inner line doc (but with a bang at the beginning)
+
+    /*!  - Inner block doc */
+    /*!! - Still an inner block doc (but with a bang at the beginning) */
+
+    //   - Only a comment
+    ///  - Outer line doc (exactly 3 slashes)
+    //// - Only a comment
+
+    /*   - Only a comment */
+    /**  - Outer block doc (exactly) 2 asterisks */
+    /*** - Only a comment */
+
+    pub mod inner_module {}
+
+    pub mod nested_comments {
+        /* In Rust /* we can /* nest comments */ */ */
+
+        // All three types of block comments can contain or be nested inside
+        // any other type:
+
+        /*   /* */  /** */  /*! */  */
+        /*!  /* */  /** */  /*! */  */
+        /**  /* */  /** */  /*! */  */
+        pub mod dummy_item {}
+    }
+
+    pub mod degenerate_cases {
+        // empty inner line doc
+        //!
+
+        // empty inner block doc
+        /*!*/
+
+        // empty line comment
+        //
+
+        // empty outer line doc
+        ///
+
+        // empty block comment
+        /**/
+
+        pub mod dummy_item {}
+
+        // empty 2-asterisk block isn't a doc block, it is a block comment
+        /***/
+
+    }
+
+    /* The next one isn't allowed because outer doc comments
+       require an item that will receive the doc */
+
+    /// Where is my item?
+}
+"##;
+    let expected = "
+//! A doc comment that applies to the implicit anonymous module of this crate
+
+pub mod outer_module {
+
+    //!  - Inner line doc
+    //!! - Still an inner line doc (but with a bang at the beginning)
+
+    /*!  - Inner block doc */
+    /*!! - Still an inner block doc (but with a bang at the beginning) */
+
+    //   - Only a comment
+    ///  - Outer line doc (exactly 3 slashes)
+    //// - Only a comment
+
+    /*   - Only a comment */
+    /**  - Outer block doc (exactly) 2 asterisks */
+    /*** - Only a comment */
+
+    pub mod inner_module {}
+
+    pub mod nested_comments {
+        /* In Rust /* we can /* nest comments */ */ */
+
+        // All three types of block comments can contain or be nested inside
+        // any other type:
+
+        /*   /* */  /** */  /*! */  */
+        /*!  /* */  /** */  /*! */  */
+        /**  /* */  /** */  /*! */  */
+        pub mod dummy_item {}
+    }
+
+    pub mod degenerate_cases {
+        // empty inner line doc
+        //!
+
+        // empty inner block doc
+        /*!*/
+
+        // empty line comment
+        //
+
+        // empty outer line doc
+        ///
+
+        // empty block comment
+        /**/
+
+        pub mod dummy_item {}
+
+        // empty 2-asterisk block isn't a doc block, it is a block comment
+        /***/
+
+    }
+
+    /* The next one isn't allowed because outer doc comments
+       require an item that will receive the doc */
+
+    /// Where is my item?
+}
+".to_string();
+    let (output, len) = make_test(input, None, false, &opts, None);
+    assert_eq!((output, len), (expected, 0));
+}
\ No newline at end of file