about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorRichard Dodd <richard.o.dodd@gmail.com>2019-11-24 20:44:19 +0000
committerRichard Dodd <richard.o.dodd@gmail.com>2020-01-14 16:57:59 +0000
commit9864ec499ffe5621c1da47150adcfaf606ec76a4 (patch)
treeb5f00a763ee035479005df44dc3d583e59f98f75 /src/libcore/tests
parentcb6122db3fa22031c48ca6b332fc856b8d098027 (diff)
downloadrust-9864ec499ffe5621c1da47150adcfaf606ec76a4.tar.gz
rust-9864ec499ffe5621c1da47150adcfaf606ec76a4.zip
Implement `finish_non_exhaustive` for `DebugStruct`.
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/fmt/builders.rs83
-rw-r--r--src/libcore/tests/lib.rs1
2 files changed, 84 insertions, 0 deletions
diff --git a/src/libcore/tests/fmt/builders.rs b/src/libcore/tests/fmt/builders.rs
index 90a9bccda15..d8ec6764bc6 100644
--- a/src/libcore/tests/fmt/builders.rs
+++ b/src/libcore/tests/fmt/builders.rs
@@ -93,6 +93,89 @@ mod debug_struct {
             format!("{:#?}", Bar)
         );
     }
+
+    #[test]
+    fn test_only_non_exhaustive() {
+        struct Foo;
+
+        impl fmt::Debug for Foo {
+            fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+                fmt.debug_struct("Foo")
+                    .finish_non_exhaustive()
+            }
+        }
+
+
+        assert_eq!("Foo { .. }", format!("{:?}", Foo));
+        assert_eq!(
+"Foo {
+    ..
+}",
+                   format!("{:#?}", Foo));
+    }
+
+    #[test]
+    fn test_multiple_and_non_exhaustive() {
+        struct Foo;
+
+        impl fmt::Debug for Foo {
+            fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+                fmt.debug_struct("Foo")
+                    .field("bar", &true)
+                    .field("baz", &format_args!("{}/{}", 10, 20))
+                    .finish_non_exhaustive()
+            }
+        }
+
+        assert_eq!("Foo { bar: true, baz: 10/20, .. }", format!("{:?}", Foo));
+        assert_eq!(
+"Foo {
+    bar: true,
+    baz: 10/20,
+    ..
+}",
+                   format!("{:#?}", Foo));
+    }
+
+    #[test]
+    fn test_nested_non_exhaustive() {
+        struct Foo;
+
+        impl fmt::Debug for Foo {
+            fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+                fmt.debug_struct("Foo")
+                    .field("bar", &true)
+                    .field("baz", &format_args!("{}/{}", 10, 20))
+                    .finish_non_exhaustive()
+            }
+        }
+
+        struct Bar;
+
+        impl fmt::Debug for Bar {
+            fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+                fmt.debug_struct("Bar")
+                    .field("foo", &Foo)
+                    .field("hello", &"world")
+                    .finish_non_exhaustive()
+            }
+        }
+
+        assert_eq!("Bar { foo: Foo { bar: true, baz: 10/20, .. }, hello: \"world\", .. }",
+                   format!("{:?}", Bar));
+        assert_eq!(
+"Bar {
+    foo: Foo {
+        bar: true,
+        baz: 10/20,
+        ..
+    },
+    hello: \"world\",
+    ..
+}",
+                   format!("{:#?}", Bar));
+    }
+
 }
 
 mod debug_tuple {
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs
index 86cf6fc104c..8c034938c2b 100644
--- a/src/libcore/tests/lib.rs
+++ b/src/libcore/tests/lib.rs
@@ -5,6 +5,7 @@
 #![feature(core_private_bignum)]
 #![feature(core_private_diy_float)]
 #![feature(debug_map_key_value)]
+#![feature(debug_non_exhaustive)]
 #![feature(dec2flt)]
 #![feature(exact_size_is_empty)]
 #![feature(fixed_size_array)]