From 33cbf8908d4cf1c971128ee35e7bd2ea50225b63 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 6 Feb 2022 22:21:09 +0100 Subject: [PATCH] Add test for block doc comments horizontal trim --- compiler/rustc_ast/src/util/comments/tests.rs | 22 ++++++------------- src/test/rustdoc-ui/block-doc-comment.rs | 16 ++++++++++++++ src/test/rustdoc-ui/block-doc-comment.stdout | 5 +++++ 3 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 src/test/rustdoc-ui/block-doc-comment.rs create mode 100644 src/test/rustdoc-ui/block-doc-comment.stdout diff --git a/compiler/rustc_ast/src/util/comments/tests.rs b/compiler/rustc_ast/src/util/comments/tests.rs index 0b8772947e6e..11d50603a101 100644 --- a/compiler/rustc_ast/src/util/comments/tests.rs +++ b/compiler/rustc_ast/src/util/comments/tests.rs @@ -45,25 +45,17 @@ fn test_line_doc_comment() { #[test] fn test_doc_blocks() { create_default_session_globals_then(|| { + let stripped = + beautify_doc_string(Symbol::intern(" # Returns\n *\n "), CommentKind::Block); + assert_eq!(stripped.as_str(), " # Returns\n\n"); + let stripped = beautify_doc_string( - Symbol::intern( - " # Returns - * - ", - ), + Symbol::intern("\n * # Returns\n *\n "), CommentKind::Block, ); assert_eq!(stripped.as_str(), " # Returns\n\n"); - let stripped = beautify_doc_string( - Symbol::intern( - " - * # Returns - * - ", - ), - CommentKind::Block, - ); - assert_eq!(stripped.as_str(), " # Returns\n\n"); + let stripped = beautify_doc_string(Symbol::intern("\n * a\n "), CommentKind::Block); + assert_eq!(stripped.as_str(), " a\n"); }) } diff --git a/src/test/rustdoc-ui/block-doc-comment.rs b/src/test/rustdoc-ui/block-doc-comment.rs new file mode 100644 index 000000000000..c60dfa3f9518 --- /dev/null +++ b/src/test/rustdoc-ui/block-doc-comment.rs @@ -0,0 +1,16 @@ +// check-pass +// compile-flags:--test + +// This test ensures that no code block is detected in the doc comments. + +pub mod Wormhole { + /** # Returns + * + */ + pub fn foofoo() {} + /** + * # Returns + * + */ + pub fn barbar() {} +} diff --git a/src/test/rustdoc-ui/block-doc-comment.stdout b/src/test/rustdoc-ui/block-doc-comment.stdout new file mode 100644 index 000000000000..e5c27bebbdb2 --- /dev/null +++ b/src/test/rustdoc-ui/block-doc-comment.stdout @@ -0,0 +1,5 @@ + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s +