about summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-29 05:21:29 +0000
committerbors <bors@rust-lang.org>2015-03-29 05:21:29 +0000
commit227b46bdede794d5c8476b810bb1c30926bd9c04 (patch)
tree50a0c0dde28dd4deea02c40cf90c713a3075313a /src/libcoretest
parent27af78c6dddc95c7c82dc21926d6ea81562e1211 (diff)
parent3c0c8fc43a6dddda37c9e833279e0f8859a05f1c (diff)
downloadrust-227b46bdede794d5c8476b810bb1c30926bd9c04.tar.gz
rust-227b46bdede794d5c8476b810bb1c30926bd9c04.zip
Auto merge of #23810 - sfackler:debug-collections, r=alexcrichton
The collections debug helpers no longer prefix output with the
collection name, in line with the current conventions for Debug
implementations. Implementations that want to preserve the current
behavior can simply add a `try!(write!(fmt, "TypeName "));` at the
beginning of the `fmt` method.

[breaking-change]
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/fmt/builders.rs157
1 files changed, 127 insertions, 30 deletions
diff --git a/src/libcoretest/fmt/builders.rs b/src/libcoretest/fmt/builders.rs
index b2fbc90be59..885ee3f9c3b 100644
--- a/src/libcoretest/fmt/builders.rs
+++ b/src/libcoretest/fmt/builders.rs
@@ -211,12 +211,12 @@ mod debug_map {
 
         impl fmt::Debug for Foo {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_map("Foo").finish()
+                fmt.debug_map().finish()
             }
         }
 
-        assert_eq!("Foo {}", format!("{:?}", Foo));
-        assert_eq!("Foo {}", format!("{:#?}", Foo));
+        assert_eq!("{}", format!("{:?}", Foo));
+        assert_eq!("{}", format!("{:#?}", Foo));
     }
 
     #[test]
@@ -225,15 +225,15 @@ mod debug_map {
 
         impl fmt::Debug for Foo {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_map("Foo")
+                fmt.debug_map()
                     .entry(&"bar", &true)
                     .finish()
             }
         }
 
-        assert_eq!("Foo { \"bar\": true }", format!("{:?}", Foo));
+        assert_eq!("{\"bar\": true}", format!("{:?}", Foo));
         assert_eq!(
-"Foo {
+"{
     \"bar\": true
 }",
                    format!("{:#?}", Foo));
@@ -245,16 +245,16 @@ mod debug_map {
 
         impl fmt::Debug for Foo {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_map("Foo")
+                fmt.debug_map()
                     .entry(&"bar", &true)
                     .entry(&10i32, &format_args!("{}/{}", 10i32, 20i32))
                     .finish()
             }
         }
 
-        assert_eq!("Foo { \"bar\": true, 10: 10/20 }", format!("{:?}", Foo));
+        assert_eq!("{\"bar\": true, 10: 10/20}", format!("{:?}", Foo));
         assert_eq!(
-"Foo {
+"{
     \"bar\": true,
     10: 10/20
 }",
@@ -267,7 +267,7 @@ mod debug_map {
 
         impl fmt::Debug for Foo {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_map("Foo")
+                fmt.debug_map()
                     .entry(&"bar", &true)
                     .entry(&10i32, &format_args!("{}/{}", 10i32, 20i32))
                     .finish()
@@ -278,23 +278,23 @@ mod debug_map {
 
         impl fmt::Debug for Bar {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_map("Bar")
+                fmt.debug_map()
                     .entry(&"foo", &Foo)
                     .entry(&Foo, &"world")
                     .finish()
             }
         }
 
-        assert_eq!("Bar { \"foo\": Foo { \"bar\": true, 10: 10/20 }, \
-                    Foo { \"bar\": true, 10: 10/20 }: \"world\" }",
+        assert_eq!("{\"foo\": {\"bar\": true, 10: 10/20}, \
+                    {\"bar\": true, 10: 10/20}: \"world\"}",
                    format!("{:?}", Bar));
         assert_eq!(
-"Bar {
-    \"foo\": Foo {
+"{
+    \"foo\": {
         \"bar\": true,
         10: 10/20
     },
-    Foo {
+    {
         \"bar\": true,
         10: 10/20
     }: \"world\"
@@ -312,12 +312,12 @@ mod debug_set {
 
         impl fmt::Debug for Foo {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_set("Foo").finish()
+                fmt.debug_set().finish()
             }
         }
 
-        assert_eq!("Foo {}", format!("{:?}", Foo));
-        assert_eq!("Foo {}", format!("{:#?}", Foo));
+        assert_eq!("{}", format!("{:?}", Foo));
+        assert_eq!("{}", format!("{:#?}", Foo));
     }
 
     #[test]
@@ -326,15 +326,15 @@ mod debug_set {
 
         impl fmt::Debug for Foo {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_set("Foo")
+                fmt.debug_set()
                     .entry(&true)
                     .finish()
             }
         }
 
-        assert_eq!("Foo { true }", format!("{:?}", Foo));
+        assert_eq!("{true}", format!("{:?}", Foo));
         assert_eq!(
-"Foo {
+"{
     true
 }",
                    format!("{:#?}", Foo));
@@ -346,16 +346,16 @@ mod debug_set {
 
         impl fmt::Debug for Foo {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_set("Foo")
+                fmt.debug_set()
                     .entry(&true)
                     .entry(&format_args!("{}/{}", 10i32, 20i32))
                     .finish()
             }
         }
 
-        assert_eq!("Foo { true, 10/20 }", format!("{:?}", Foo));
+        assert_eq!("{true, 10/20}", format!("{:?}", Foo));
         assert_eq!(
-"Foo {
+"{
     true,
     10/20
 }",
@@ -368,7 +368,7 @@ mod debug_set {
 
         impl fmt::Debug for Foo {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_set("Foo")
+                fmt.debug_set()
                     .entry(&true)
                     .entry(&format_args!("{}/{}", 10i32, 20i32))
                     .finish()
@@ -379,18 +379,18 @@ mod debug_set {
 
         impl fmt::Debug for Bar {
             fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-                fmt.debug_set("Bar")
+                fmt.debug_set()
                     .entry(&Foo)
                     .entry(&"world")
                     .finish()
             }
         }
 
-        assert_eq!("Bar { Foo { true, 10/20 }, \"world\" }",
+        assert_eq!("{{true, 10/20}, \"world\"}",
                    format!("{:?}", Bar));
         assert_eq!(
-"Bar {
-    Foo {
+"{
+    {
         true,
         10/20
     },
@@ -399,3 +399,100 @@ mod debug_set {
                    format!("{:#?}", Bar));
     }
 }
+
+mod debug_list {
+    use std::fmt;
+
+    #[test]
+    fn test_empty() {
+        struct Foo;
+
+        impl fmt::Debug for Foo {
+            fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+                fmt.debug_list().finish()
+            }
+        }
+
+        assert_eq!("[]", format!("{:?}", Foo));
+        assert_eq!("[]", format!("{:#?}", Foo));
+    }
+
+    #[test]
+    fn test_single() {
+        struct Foo;
+
+        impl fmt::Debug for Foo {
+            fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+                fmt.debug_list()
+                    .entry(&true)
+                    .finish()
+            }
+        }
+
+        assert_eq!("[true]", format!("{:?}", Foo));
+        assert_eq!(
+"[
+    true
+]",
+                   format!("{:#?}", Foo));
+    }
+
+    #[test]
+    fn test_multiple() {
+        struct Foo;
+
+        impl fmt::Debug for Foo {
+            fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+                fmt.debug_list()
+                    .entry(&true)
+                    .entry(&format_args!("{}/{}", 10i32, 20i32))
+                    .finish()
+            }
+        }
+
+        assert_eq!("[true, 10/20]", format!("{:?}", Foo));
+        assert_eq!(
+"[
+    true,
+    10/20
+]",
+                   format!("{:#?}", Foo));
+    }
+
+    #[test]
+    fn test_nested() {
+        struct Foo;
+
+        impl fmt::Debug for Foo {
+            fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+                fmt.debug_list()
+                    .entry(&true)
+                    .entry(&format_args!("{}/{}", 10i32, 20i32))
+                    .finish()
+            }
+        }
+
+        struct Bar;
+
+        impl fmt::Debug for Bar {
+            fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+                fmt.debug_list()
+                    .entry(&Foo)
+                    .entry(&"world")
+                    .finish()
+            }
+        }
+
+        assert_eq!("[[true, 10/20], \"world\"]",
+                   format!("{:?}", Bar));
+        assert_eq!(
+"[
+    [
+        true,
+        10/20
+    ],
+    \"world\"
+]",
+                   format!("{:#?}", Bar));
+    }
+}