From 4e9a63ff917af32bd9ddfee65f5871a5586771e1 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 26 Mar 2013 17:42:01 -0700 Subject: [PATCH] std: add tests for decoding json enums --- src/libstd/json.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libstd/json.rs b/src/libstd/json.rs index dc9f629d7e2..968c6d9e58b 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -851,7 +851,6 @@ fn read_managed(&self, f: &fn() -> T) -> T { fn read_enum(&self, name: &str, f: &fn() -> T) -> T { debug!("read_enum(%s)", name); - if name != ~"option" { fail!(~"only supports the option enum") } f() } @@ -1720,6 +1719,20 @@ fn test_read_some() { assert_eq!(value, Some(~"jodhpurs")); } + #[test] + fn test_read_enum_no_args() { + let decoder = Decoder(from_str(~"\"Dog\"").unwrap()); + let value: Animal = Decodable::decode(&decoder); + assert_eq!(value, Dog); + } + + #[test] + fn test_read_enum_multiple_args() { + let decoder = Decoder(from_str(~"[\"Frog\",\"Henry\",349]").unwrap()); + let value: Animal = Decodable::decode(&decoder); + assert_eq!(value, Frog(~"Henry", 349)); + } + #[test] fn test_multiline_errors() { assert_eq!(from_str(~"{\n \"foo\":\n \"bar\""),