提交 4e9a63ff 编写于 作者: E Erick Tryzelaar

std: add tests for decoding json enums

上级 4d6dcefc
......@@ -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\""),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册