Skip to content

Commit 3abf3a5

Browse files
committed
add tests, bytes -> chars
1 parent 6edacd4 commit 3abf3a5

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/system.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::fs;
1919
use std::io::{self, BufRead, BufReader, Read};
2020
use std::iter::Peekable;
2121
use std::path::{Path, PathBuf};
22-
use std::str::Bytes;
22+
use std::str::Chars;
2323

2424
use rustfmt::*;
2525
use rustfmt::filemap::{write_system_newlines, FileMap};
@@ -436,22 +436,22 @@ fn rustfmt_diff_no_diff_test() {
436436

437437
// Compare strings without distinguishing between CRLF and LF
438438
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());
441441
left.eq(right)
442442
}
443443

444-
struct BytesIgnoreNewlineRepr<'a>(Peekable<Bytes<'a>>);
444+
struct CharsIgnoreNewlineRepr<'a>(Peekable<Chars<'a>>);
445445

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' {
451451
self.0.next();
452-
b'\n'
452+
'\n'
453453
} else {
454-
b'\r'
454+
'\r'
455455
}
456456
} else {
457457
c
@@ -461,5 +461,10 @@ impl<'a> Iterator for BytesIgnoreNewlineRepr<'a> {
461461

462462
#[test]
463463
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", ""));
464467
assert!(string_eq_ignore_newline_repr("a\nb\nc\rd", "a\nb\r\nc\rd"));
468+
assert!(string_eq_ignore_newline_repr("a\r\n\r\n\r\nb", "a\n\n\nb"));
469+
assert!(!string_eq_ignore_newline_repr("a\r\nbcd", "a\nbcdefghijk"));
465470
}

0 commit comments

Comments
 (0)