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).
@@ -33,11 +40,12 @@ pub fn rewrite_comment(orig: &str, block_style: bool, width: usize, offset: usiz
33
40
line_start : line_start,
34
41
line_end : "" ,
35
42
width : max_chars,
36
- offset : offset + opener. len ( ) - line_start. len ( ) ,
43
+ offset : offset + ( opener. len ( ) - line_start. len ( ) ) ,
37
44
trim_end : true ,
45
+ config : config,
38
46
} ;
39
47
40
- let indent_str = make_indent ( offset) ;
48
+ let indent_str = make_indent ( offset, config ) ;
41
49
let line_breaks = s. chars ( ) . filter ( |& c| c == '\n' ) . count ( ) ;
42
50
43
51
let ( _, mut s) = s. lines ( )
@@ -288,24 +296,33 @@ impl<T> Iterator for CharClasses<T> where T: Iterator, T::Item: RichChar {
288
296
mod test {
289
297
use super :: { CharClasses , CodeCharKind , contains_comment, rewrite_comment, FindUncommented } ;
290
298
299
+ use std:: default:: Default ;
300
+
301
+ use Indent ;
302
+
291
303
#[ test]
292
304
fn format_comments ( ) {
293
- assert_eq ! ( "/* test */" , rewrite_comment( " //test" , true , 100 , 100 ) ) ;
294
- assert_eq ! ( "// comment\n // on a" , rewrite_comment( "// comment on a" , false , 10 , 0 ) ) ;
305
+ let config = Default :: default ( ) ;
306
+ assert_eq ! ( "/* test */" , rewrite_comment( " //test" , true , 100 , Indent :: new( 0 , 100 ) ,
307
+ & config) ) ;
308
+ assert_eq ! ( "// comment\n // on a" , rewrite_comment( "// comment on a" , false , 10 ,
309
+ Indent :: new( 0 , 0 ) , & config) ) ;
295
310
296
311
assert_eq ! ( "// A multi line comment\n // between args." ,
297
312
rewrite_comment( "// A multi line comment\n // between args." ,
298
313
false ,
299
314
60 ,
300
- 12 ) ) ;
315
+ Indent :: new( 0 , 12 ) ,
316
+ & config) ) ;
301
317
302
318
let input = "// comment" ;
303
319
let expected = "/* com\n \
304
320
* men\n \
305
321
* t */";
306
- assert_eq ! ( expected, rewrite_comment( input, true , 9 , 69 ) ) ;
322
+ assert_eq ! ( expected, rewrite_comment( input, true , 9 , Indent :: new ( 0 , 69 ) , & config ) ) ;
307
323
308
- assert_eq ! ( "/* trimmed */" , rewrite_comment( "/* trimmed */" , true , 100 , 100 ) ) ;
324
+ assert_eq ! ( "/* trimmed */" , rewrite_comment( "/* trimmed */" , true , 100 ,
325
+ Indent :: new( 0 , 100 ) , & config) ) ;
309
326
}
310
327
311
328
// This is probably intended to be a non-test fn, but it is not used. I'm
0 commit comments