mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 08:37:14 +00:00
std: add tests for decoding json enums
This commit is contained in:
parent
4d6dcefcbb
commit
4e9a63ff91
|
@ -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\""),
|
||||
|
|
Loading…
Reference in a new issue