From 3ff116ea84b4732a1e3f2d0ae3a7d6902f964a77 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 23 Jun 2014 08:50:00 -0700 Subject: Add a test for a missing field --- src/serialization.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/serialization.rs b/src/serialization.rs index f610f6e..028de64 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -822,7 +822,7 @@ mod tests { } #[test] - fn errors() { + fn type_errors() { #[deriving(Encodable, Decodable, PartialEq, Show)] struct Foo { bar: int } @@ -839,4 +839,22 @@ mod tests { } } } + + #[test] + fn missing_errors() { + #[deriving(Encodable, Decodable, PartialEq, Show)] + struct Foo { bar: int } + + let mut d = Decoder::new(Table(map! { + })); + let a: Result = Decodable::decode(&mut d); + match a { + Ok(..) => fail!("should not have decoded"), + Err(e) => { + assert_eq!(e.desc.as_slice(), + "for field `bar` expected type `integer`, but \ + found no value"); + } + } + } } -- cgit v1.2.3