@@ -19,7 +19,7 @@ use std::fs;
19
19
use std:: io:: { self , BufRead , BufReader , Read } ;
20
20
use std:: iter:: Peekable ;
21
21
use std:: path:: { Path , PathBuf } ;
22
- use std:: str:: Bytes ;
22
+ use std:: str:: Chars ;
23
23
24
24
use rustfmt:: * ;
25
25
use rustfmt:: filemap:: { write_system_newlines, FileMap } ;
@@ -436,22 +436,22 @@ fn rustfmt_diff_no_diff_test() {
436
436
437
437
// Compare strings without distinguishing between CRLF and LF
438
438
fn string_eq_ignore_newline_repr ( left : & str , right : & str ) -> bool {
439
- let left = BytesIgnoreNewlineRepr ( left. bytes ( ) . peekable ( ) ) ;
440
- let right = BytesIgnoreNewlineRepr ( right. bytes ( ) . peekable ( ) ) ;
439
+ let left = CharsIgnoreNewlineRepr ( left. chars ( ) . peekable ( ) ) ;
440
+ let right = CharsIgnoreNewlineRepr ( right. chars ( ) . peekable ( ) ) ;
441
441
left. eq ( right)
442
442
}
443
443
444
- struct BytesIgnoreNewlineRepr < ' a > ( Peekable < Bytes < ' a > > ) ;
444
+ struct CharsIgnoreNewlineRepr < ' a > ( Peekable < Chars < ' a > > ) ;
445
445
446
- impl < ' a > Iterator for BytesIgnoreNewlineRepr < ' a > {
447
- type Item = u8 ;
448
- fn next ( & mut self ) -> Option < u8 > {
449
- self . 0 . next ( ) . map ( |c| if c == b '\r' {
450
- if * self . 0 . peek ( ) . unwrap_or ( & 0 ) == b '\n' {
446
+ impl < ' a > Iterator for CharsIgnoreNewlineRepr < ' a > {
447
+ type Item = char ;
448
+ fn next ( & mut self ) -> Option < char > {
449
+ self . 0 . next ( ) . map ( |c| if c == '\r' {
450
+ if * self . 0 . peek ( ) . unwrap_or ( & '\0' ) == '\n' {
451
451
self . 0 . next ( ) ;
452
- b '\n'
452
+ '\n'
453
453
} else {
454
- b '\r'
454
+ '\r'
455
455
}
456
456
} else {
457
457
c
@@ -461,5 +461,10 @@ impl<'a> Iterator for BytesIgnoreNewlineRepr<'a> {
461
461
462
462
#[ test]
463
463
fn string_eq_ignore_newline_repr_test ( ) {
464
+ assert ! ( string_eq_ignore_newline_repr( "" , "" ) ) ;
465
+ assert ! ( !string_eq_ignore_newline_repr( "" , "abc" ) ) ;
466
+ assert ! ( !string_eq_ignore_newline_repr( "abc" , "" ) ) ;
464
467
assert ! ( string_eq_ignore_newline_repr( "a\n b\n c\r d" , "a\n b\r \n c\r d" ) ) ;
468
+ assert ! ( string_eq_ignore_newline_repr( "a\r \n \r \n \r \n b" , "a\n \n \n b" ) ) ;
469
+ assert ! ( !string_eq_ignore_newline_repr( "a\r \n bcd" , "a\n bcdefghijk" ) ) ;
465
470
}
0 commit comments