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