std: add tests for decoding json enums

This commit is contained in:
Erick Tryzelaar 2013-03-26 17:42:01 -07:00
parent 4d6dcefcbb
commit 4e9a63ff91

View file

@ -851,7 +851,6 @@ fn read_managed<T>(&self, f: &fn() -> T) -> T {
fn read_enum<T>(&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\""),