12
12
13
13
use std:: iter;
14
14
15
+ use Indent ;
16
+ use config:: Config ;
15
17
use string:: { StringFormat , rewrite_string} ;
16
- use utils:: make_indent;
17
18
18
- pub fn rewrite_comment ( orig : & str , block_style : bool , width : usize , offset : usize ) -> String {
19
+ pub fn rewrite_comment ( orig : & str ,
20
+ block_style : bool ,
21
+ width : usize ,
22
+ offset : Indent ,
23
+ config : & Config )
24
+ -> String {
19
25
let s = orig. trim ( ) ;
20
26
21
27
// Edge case: block comments. Let's not trim their lines (for now).
@@ -33,11 +39,12 @@ pub fn rewrite_comment(orig: &str, block_style: bool, width: usize, offset: usiz
33
39
line_start : line_start,
34
40
line_end : "" ,
35
41
width : max_chars,
36
- offset : offset + opener. len ( ) - line_start. len ( ) ,
42
+ offset : offset + ( opener. len ( ) - line_start. len ( ) ) ,
37
43
trim_end : true ,
44
+ config : config,
38
45
} ;
39
46
40
- let indent_str = make_indent ( offset) ;
47
+ let indent_str = offset. to_string ( config ) ;
41
48
let line_breaks = s. chars ( ) . filter ( |& c| c == '\n' ) . count ( ) ;
42
49
43
50
let ( _, mut s) = s. lines ( )
@@ -288,27 +295,32 @@ impl<T> Iterator for CharClasses<T> where T: Iterator, T::Item: RichChar {
288
295
mod test {
289
296
use super :: { CharClasses , CodeCharKind , contains_comment, rewrite_comment, FindUncommented } ;
290
297
291
- // FIXME(#217): prevent string literal from going over the limit.
298
+ use Indent ;
292
299
#[ test]
293
300
#[ rustfmt_skip]
294
301
fn format_comments ( ) {
295
- assert_eq ! ( "/* test */" , rewrite_comment( " //test" , true , 100 , 100 ) ) ;
296
- assert_eq ! ( "// comment\n // on a" , rewrite_comment( "// comment on a" , false , 10 , 0 ) ) ;
302
+ let config = Default :: default ( ) ;
303
+ assert_eq ! ( "/* test */" , rewrite_comment( " //test" , true , 100 , Indent :: new( 0 , 100 ) ,
304
+ & config) ) ;
305
+ assert_eq ! ( "// comment\n // on a" , rewrite_comment( "// comment on a" , false , 10 ,
306
+ Indent :: empty( ) , & config) ) ;
297
307
298
308
assert_eq ! ( "// A multi line comment\n // between args." ,
299
309
rewrite_comment( "// A multi line comment\n // between args." ,
300
310
false ,
301
311
60 ,
302
- 12 ) ) ;
312
+ Indent :: new( 0 , 12 ) ,
313
+ & config) ) ;
303
314
304
315
let input = "// comment" ;
305
316
let expected =
306
317
"/* com\n \
307
318
* men\n \
308
319
* t */";
309
- assert_eq ! ( expected, rewrite_comment( input, true , 9 , 69 ) ) ;
320
+ assert_eq ! ( expected, rewrite_comment( input, true , 9 , Indent :: new ( 0 , 69 ) , & config ) ) ;
310
321
311
- assert_eq ! ( "/* trimmed */" , rewrite_comment( "/* trimmed */" , true , 100 , 100 ) ) ;
322
+ assert_eq ! ( "/* trimmed */" , rewrite_comment( "/* trimmed */" , true , 100 ,
323
+ Indent :: new( 0 , 100 ) , & config) ) ;
312
324
}
313
325
314
326
// This is probably intended to be a non-test fn, but it is not used. I'm
0 commit comments