]> git.lizzy.rs Git - rust.git/commitdiff
Make {char, str}::escape_debug and impl Debug for {char, str} consistent
authorvarkor <github@varkor.com>
Wed, 16 May 2018 22:20:22 +0000 (23:20 +0100)
committervarkor <github@varkor.com>
Mon, 21 May 2018 17:57:54 +0000 (18:57 +0100)
src/liballoc/tests/str.rs
src/libcore/fmt/mod.rs
src/libcore/tests/char.rs

index 1a47e5433ea90d97455c7c8cf8a3ddb556dff6b1..2f38c8b3ae21e9ae0ac6e8523b90cffd98d35792 100644 (file)
@@ -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}bé\u{e000}".escape_debug(), "\\u{301}a\\u{301}bé\\u{e000}");
 }
 
 #[test]
index 1cfde5131026a0b698ce81240ccd7f44d3676f70..5820fe58932c6967b5797ca8112dd808e813d270 100644 (file)
@@ -1844,14 +1844,8 @@ fn fmt(&self, f: &mut Formatter) -> Result {
 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('\'')
     }
index 76f28d493ab9483aab319b78651baca17cdb5732..d19e3b527696f93f942f248e65c69dde347db611 100644 (file)
@@ -181,19 +181,12 @@ fn string(c: char) -> String {
     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 {