Add tests for printing of NonZero-optimized enums in Rust
authorManish Goregaokar <manish@mozilla.com>
Sat, 25 Jun 2016 05:40:38 +0000 (11:10 +0530)
committerManish Goregaokar <manish@mozilla.com>
Sat, 25 Jun 2016 05:56:59 +0000 (11:26 +0530)
gdb/testsuite/ChangeLog:
2016-06-25  Manish Goregaokar  <manish@mozilla.com>

    PR gdb/20239
    * gdb.rust/simple.rs: Add more tests for printing NonZero enums.
    * gdb.rust/simple.exp: Add test expectations for new NonZero tests.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/simple.exp
gdb/testsuite/gdb.rust/simple.rs

index 86799654eea586e7f05db23eadbbdc64a3d85886..0db0fc2d1febb78fba73c8b826420551f2c2f710 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-25  Manish Goregaokar  <manish@mozilla.com>
+
+       PR gdb/20239
+       * gdb.rust/simple.rs: Add more tests for printing NonZero enums.
+       * gdb.rust/simple.exp: Add test expectations for new NonZero tests.
+
 2016-06-24  David Taylor  <dtaylor@emc.com>
 
        * gdb.base/offsets.exp: New file.
index a4a2190442683919a4027ecc28d8ca0d689e83e3..88f1c89a748dccffebe4d9b3aa0e63935a073624 100644 (file)
@@ -169,6 +169,17 @@ gdb_test "print ..5" " = .*::ops::RangeTo.* \\{end: 5\\}"
 gdb_test "print 5.." " = .*::ops::RangeFrom.* \\{start: 5\\}"
 gdb_test "print .." " = .*::ops::RangeFull"
 
+gdb_test "print str_some" \
+    " = core::option::Option<collections::string::String>::Some\\(collections::string::String .*"
+gdb_test "print str_none" " = core::option::Option<collections::string::String>::None"
+gdb_test "print int_some" " = core::option::Option::Some\\(1\\)"
+gdb_test "print int_none" " = core::option::Option::None"
+gdb_test "print box_some" " = core::option::Option<Box<u8>>::Some\\(.*\\)"
+gdb_test "print box_none" " = core::option::Option<Box<u8>>::None"
+gdb_test "print custom_some" \
+    " = simple::NonZeroOptimized::Value\\(collections::string::String .*"
+gdb_test "print custom_none" " = simple::NonZeroOptimized::Empty"
+
 proc test_one_slice {svar length base range} {
     global hex
 
index 6d6395a8c336adbccdd4e46adb336850c51a8216..32da5807b7f3f044e562cce44699950d4b0c0b50 100644 (file)
@@ -38,6 +38,12 @@ enum MoreComplicated {
     Four{this: bool, is: u8, a: char, struct_: u64, variant: u32},
 }
 
+// tests the nonzero optimization, but fields are reversed
+enum NonZeroOptimized {
+    Empty,
+    Value(String),
+}
+
 fn diff2(x: i32, y: i32) -> i32 {
     x - y
 }
@@ -92,6 +98,17 @@ fn main () {
     let to1 = &w[..3];
     let to2 = &slice[..1];
 
+    // tests for enum optimizations
+
+    let str_some = Some("hi".to_string());
+    let str_none = None::<String>;
+    let box_some = Some(Box::new(1u8));
+    let box_none = None::<Box<u8>>;
+    let int_some = Some(1u8);
+    let int_none = None::<u8>;
+    let custom_some = NonZeroOptimized::Value("hi".into());
+    let custom_none = NonZeroOptimized::Empty;
+
     println!("{}, {}", x.0, x.1);        // set breakpoint here
     println!("{}", diff2(92, 45));
 }