about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2013-10-16 21:36:41 -0400
committerCorey Richardson <corey@octayn.net>2013-10-16 21:36:41 -0400
commit75cedf8e62a0c8d8bfd9e15d4a1d3b554eccbdc2 (patch)
tree495db5b60f4e933c2f2b319a948a13d3e8fbed9d /src
parent023466cccaf2230b6f2beb3e9e9802e6be1f29d9 (diff)
downloadrust-75cedf8e62a0c8d8bfd9e15d4a1d3b554eccbdc2.tar.gz
rust-75cedf8e62a0c8d8bfd9e15d4a1d3b554eccbdc2.zip
uuid: serialize test and documentations
Diffstat (limited to 'src')
-rw-r--r--src/libextra/uuid.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/libextra/uuid.rs b/src/libextra/uuid.rs
index c3b67ae0a0c..345cf64f128 100644
--- a/src/libextra/uuid.rs
+++ b/src/libextra/uuid.rs
@@ -488,14 +488,16 @@ impl TotalEq for Uuid {
     }
 }
 
-// FIXME #9845: Test these
+// FIXME #9845: Test these more thoroughly
 impl<T: Encoder> Encodable<T> for Uuid {
+    /// Encode a UUID as a hypenated string
     fn encode(&self, e: &mut T) {
         e.emit_str(self.to_hyphenated_str());
     }
 }
 
 impl<T: Decoder> Decodable<T> for Uuid {
+    /// Decode a UUID from a string
     fn decode(d: &mut T) -> Uuid {
         from_str(d.read_str()).unwrap()
     }
@@ -785,6 +787,20 @@ mod test {
         assert!(ub.len() == 16);
         assert!(! ub.iter().all(|&b| b == 0));
     }
+
+    #[test]
+    fn test_serialize_round_trip() {
+        use std;
+        use ebml;
+        use serialize::{Encodable, Decodable};
+
+        let u = Uuid::new_v4();
+        let bytes = do std::io::with_bytes_writer |wr| {
+            u.encode(&mut ebml::writer::Encoder(wr));
+        };
+        let u2 = Decodable::decode(&mut ebml::reader::Decoder(ebml::reader::Doc(@bytes)));
+        assert_eq!(u, u2);
+    }
 }
 
 #[cfg(test)]