Skip to content

Commit

Permalink
Make {char, str}::escape_debug and impl Debug for {char, str} consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed May 21, 2018
1 parent d7aa35e commit 8c89e7f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/liballoc/tests/str.rs
Expand Up @@ -999,6 +999,7 @@ fn test_escape_debug() {
assert_eq!("\u{10000}\u{10ffff}".escape_debug(), "\u{10000}\\u{10ffff}");
assert_eq!("ab\u{200b}".escape_debug(), "ab\\u{200b}");
assert_eq!("\u{10d4ea}\r".escape_debug(), "\\u{10d4ea}\\r");
assert_eq!("\u{301}a\u{301}\u{e000}".escape_debug(), "\\u{301}a\\u{301}bé\\u{e000}");
}

#[test]
Expand Down
10 changes: 2 additions & 8 deletions src/libcore/fmt/mod.rs
Expand Up @@ -1844,14 +1844,8 @@ impl Display for str {
impl Debug for char {
fn fmt(&self, f: &mut Formatter) -> Result {
f.write_char('\'')?;
if self.is_nonspacing_mark() {
for c in self.escape_unicode() {
f.write_char(c)?
}
} else {
for c in self.escape_debug() {
f.write_char(c)?
}
for c in self.escape_debug() {
f.write_char(c)?
}
f.write_char('\'')
}
Expand Down
9 changes: 1 addition & 8 deletions src/libcore/tests/char.rs
Expand Up @@ -181,19 +181,12 @@ fn test_escape_debug() {
assert_eq!(string('\u{ff}'), "\u{ff}");
assert_eq!(string('\u{11b}'), "\u{11b}");
assert_eq!(string('\u{1d4b6}'), "\u{1d4b6}");
assert_eq!(string('\u{301}'), "'\\u{301}'"); // combining character
assert_eq!(string('\u{200b}'),"\\u{200b}"); // zero width space
assert_eq!(string('\u{e000}'), "\\u{e000}"); // private use 1
assert_eq!(string('\u{100000}'), "\\u{100000}"); // private use 2
}

#[test]
fn test_debug() {
assert_eq!(format!("{:?}", 'a'), "'a'"); // ASCII character
assert_eq!(format!("{:?}", 'é'), "'é'"); // printable character
assert_eq!(format!("{:?}", '\u{301}'), "'\\u{301}'"); // combining character
assert_eq!(format!("{:?}", '\u{e000}'), "'\\u{e000}'"); // private use 1
}

#[test]
fn test_escape_default() {
fn string(c: char) -> String {
Expand Down

0 comments on commit 8c89e7f

Please sign in to comment.