mirror of
https://github.com/rust-lang/rust
synced 2024-11-02 11:53:40 +00:00
std: add tests for decoding json enums
This commit is contained in:
parent
4d6dcefcbb
commit
4e9a63ff91
1 changed files with 14 additions and 1 deletions
|
@ -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