uuid: serialize test and documentations

This commit is contained in:
Corey Richardson 2013-10-16 21:36:41 -04:00
parent 023466ccca
commit 75cedf8e62

View File

@ -488,14 +488,16 @@ fn equals(&self, other: &Uuid) -> bool {
}
}
// 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 @@ fn test_rand_rand() {
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)]