std: Add tests for json decoding options
This commit is contained in:
@@ -1236,6 +1236,8 @@ mod tests {
|
||||
use core::prelude::*;
|
||||
use core::hashmap::linear::LinearMap;
|
||||
|
||||
use std::serialize::Decodable;
|
||||
|
||||
fn mk_object(items: &[(~str, Json)]) -> Json {
|
||||
let mut d = ~LinearMap::new();
|
||||
|
||||
@@ -1389,6 +1391,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
#[deriving(Eq)]
|
||||
enum Animal {
|
||||
Dog,
|
||||
Frog(~str, int)
|
||||
@@ -1706,6 +1710,20 @@ mod tests {
|
||||
]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_none() {
|
||||
let decoder = Decoder(from_str(~"null").unwrap());
|
||||
let value: Option<~str> = Decodable::decode(&decoder);
|
||||
assert_eq!(value, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_some() {
|
||||
let decoder = Decoder(from_str(~"\"jodhpurs\"").unwrap());
|
||||
let value: Option<~str> = Decodable::decode(&decoder);
|
||||
assert_eq!(value, Some(~"jodhpurs"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiline_errors() {
|
||||
assert_eq!(from_str(~"{\n \"foo\":\n \"bar\""),
|
||||
|
||||
Reference in New Issue
Block a user