File tree 2 files changed +27
-4
lines changed
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -173,7 +173,7 @@ fn test_doc_comment_single_line_block_strips_suffix_whitespace() {
173
173
. ok ( )
174
174
. unwrap ( ) ;
175
175
let module = file. syntax ( ) . descendants ( ) . find_map ( Module :: cast) . unwrap ( ) ;
176
- assert_eq ! ( "this is mod foo" , module. doc_comment_text( ) . unwrap( ) ) ;
176
+ assert_eq ! ( "this is mod foo " , module. doc_comment_text( ) . unwrap( ) ) ;
177
177
}
178
178
179
179
#[ test]
@@ -191,7 +191,27 @@ fn test_doc_comment_multi_line_block_strips_suffix() {
191
191
. ok ( )
192
192
. unwrap ( ) ;
193
193
let module = file. syntax ( ) . descendants ( ) . find_map ( Module :: cast) . unwrap ( ) ;
194
- assert_eq ! ( " this\n is\n mod foo" , module. doc_comment_text( ) . unwrap( ) ) ;
194
+ assert_eq ! (
195
+ " this\n is\n mod foo\n " ,
196
+ module. doc_comment_text( ) . unwrap( )
197
+ ) ;
198
+ }
199
+
200
+ #[ test]
201
+ fn test_comments_preserve_trailing_whitespace ( ) {
202
+ let file = SourceFile :: parse (
203
+ r#"
204
+ /// Representation of a Realm.
205
+ /// In the specification these are called Realm Records.
206
+ struct Realm {}"# ,
207
+ )
208
+ . ok ( )
209
+ . unwrap ( ) ;
210
+ let def = file. syntax ( ) . descendants ( ) . find_map ( StructDef :: cast) . unwrap ( ) ;
211
+ assert_eq ! (
212
+ "Representation of a Realm. \n In the specification these are called Realm Records." ,
213
+ def. doc_comment_text( ) . unwrap( )
214
+ ) ;
195
215
}
196
216
197
217
#[ test]
Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ pub trait DocCommentsOwner: AstNode {
120
120
has_comments = true ;
121
121
let prefix_len = comment. prefix ( ) . len ( ) ;
122
122
123
- let line = comment. text ( ) . as_str ( ) ;
123
+ let line: & str = comment. text ( ) . as_str ( ) ;
124
124
125
125
// Determine if the prefix or prefix + 1 char is stripped
126
126
let pos =
@@ -136,7 +136,10 @@ pub trait DocCommentsOwner: AstNode {
136
136
line. len ( )
137
137
} ;
138
138
139
- line[ pos..end] . trim_end ( ) . to_owned ( )
139
+ // Note that we do not trim the end of the line here
140
+ // since whitespace can have special meaning at the end
141
+ // of a line in markdown.
142
+ line[ pos..end] . to_owned ( )
140
143
} )
141
144
. join ( "\n " ) ;
142
145
You can’t perform that action at this time.
0 commit comments