Skip to content

Commit 697ef30

Browse files
committed
Merge branch 'win-test-crlf' of https://github.com/wada314/rustfmt into win-test-crlf
2 parents 9c4c849 + c41b451 commit 697ef30

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/system.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ use std::fs;
1919
use std::io::{self, BufRead, BufReader, Read};
2020
use std::iter::Peekable;
2121
use std::path::{Path, PathBuf};
22+
<<<<<<< HEAD
2223
use std::str::Chars;
24+
=======
25+
use std::str::Bytes;
26+
>>>>>>> c41b45169a6a8b461d6615fb59ade61182daf5f5
2327

2428
use rustfmt::*;
2529
use rustfmt::filemap::{write_system_newlines, FileMap};
@@ -436,6 +440,7 @@ fn rustfmt_diff_no_diff_test() {
436440

437441
// Compare strings without distinguishing between CRLF and LF
438442
fn string_eq_ignore_newline_repr(left: &str, right: &str) -> bool {
443+
<<<<<<< HEAD
439444
let left = CharsIgnoreNewlineRepr(left.chars().peekable());
440445
let right = CharsIgnoreNewlineRepr(right.chars().peekable());
441446
left.eq(right)
@@ -452,6 +457,24 @@ impl<'a> Iterator for CharsIgnoreNewlineRepr<'a> {
452457
'\n'
453458
} else {
454459
'\r'
460+
=======
461+
let left = BytesIgnoreNewlineRepr(left.bytes().peekable());
462+
let right = BytesIgnoreNewlineRepr(right.bytes().peekable());
463+
left.eq(right)
464+
}
465+
466+
struct BytesIgnoreNewlineRepr<'a>(Peekable<Bytes<'a>>);
467+
468+
impl<'a> Iterator for BytesIgnoreNewlineRepr<'a> {
469+
type Item = u8;
470+
fn next(&mut self) -> Option<u8> {
471+
self.0.next().map(|c| if c == b'\r' {
472+
if *self.0.peek().unwrap_or(&0) == b'\n' {
473+
self.0.next();
474+
b'\n'
475+
} else {
476+
b'\r'
477+
>>>>>>> c41b45169a6a8b461d6615fb59ade61182daf5f5
455478
}
456479
} else {
457480
c
@@ -461,10 +484,14 @@ impl<'a> Iterator for CharsIgnoreNewlineRepr<'a> {
461484

462485
#[test]
463486
fn string_eq_ignore_newline_repr_test() {
487+
<<<<<<< HEAD
464488
assert!(string_eq_ignore_newline_repr("", ""));
465489
assert!(!string_eq_ignore_newline_repr("", "abc"));
466490
assert!(!string_eq_ignore_newline_repr("abc", ""));
467491
assert!(string_eq_ignore_newline_repr("a\nb\nc\rd", "a\nb\r\nc\rd"));
468492
assert!(string_eq_ignore_newline_repr("a\r\n\r\n\r\nb", "a\n\n\nb"));
469493
assert!(!string_eq_ignore_newline_repr("a\r\nbcd", "a\nbcdefghijk"));
494+
=======
495+
assert!(string_eq_ignore_newline_repr("a\nb\nc\rd", "a\nb\r\nc\rd"));
496+
>>>>>>> c41b45169a6a8b461d6615fb59ade61182daf5f5
470497
}

0 commit comments

Comments
 (0)