std: Add tests for json decoding options
This commit is contained in:
parent
c9188c8301
commit
b10b8c3ee4
2 changed files with 42 additions and 13 deletions
|
@ -1236,6 +1236,8 @@ mod tests {
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
use core::hashmap::linear::LinearMap;
|
use core::hashmap::linear::LinearMap;
|
||||||
|
|
||||||
|
use std::serialize::Decodable;
|
||||||
|
|
||||||
fn mk_object(items: &[(~str, Json)]) -> Json {
|
fn mk_object(items: &[(~str, Json)]) -> Json {
|
||||||
let mut d = ~LinearMap::new();
|
let mut d = ~LinearMap::new();
|
||||||
|
|
||||||
|
@ -1389,6 +1391,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[auto_encode]
|
#[auto_encode]
|
||||||
|
#[auto_decode]
|
||||||
|
#[deriving(Eq)]
|
||||||
enum Animal {
|
enum Animal {
|
||||||
Dog,
|
Dog,
|
||||||
Frog(~str, int)
|
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]
|
#[test]
|
||||||
fn test_multiline_errors() {
|
fn test_multiline_errors() {
|
||||||
assert_eq!(from_str(~"{\n \"foo\":\n \"bar\""),
|
assert_eq!(from_str(~"{\n \"foo\":\n \"bar\""),
|
||||||
|
|
|
@ -326,18 +326,29 @@ mod test {
|
||||||
@~"fn foo (x : int) { x; }",
|
@~"fn foo (x : int) { x; }",
|
||||||
~[],
|
~[],
|
||||||
new_parse_sess(None));
|
new_parse_sess(None));
|
||||||
assert_eq!(to_json_str(@tts),
|
assert_eq!(
|
||||||
~"[[\"tt_tok\",[null,[\"IDENT\",[\"fn\",false]]]],\
|
to_json_str(@tts),
|
||||||
|
~"[\
|
||||||
|
[\"tt_tok\",[null,[\"IDENT\",[\"fn\",false]]]],\
|
||||||
[\"tt_tok\",[null,[\"IDENT\",[\"foo\",false]]]],\
|
[\"tt_tok\",[null,[\"IDENT\",[\"foo\",false]]]],\
|
||||||
[\"tt_delim\",[[[\"tt_tok\",[null,[\"LPAREN\",[]]]],\
|
[\"tt_delim\",[\
|
||||||
|
[\
|
||||||
|
[\"tt_tok\",[null,[\"LPAREN\",[]]]],\
|
||||||
[\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\
|
[\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\
|
||||||
[\"tt_tok\",[null,[\"COLON\",[]]]],\
|
[\"tt_tok\",[null,[\"COLON\",[]]]],\
|
||||||
[\"tt_tok\",[null,[\"IDENT\",[\"int\",false]]]],\
|
[\"tt_tok\",[null,[\"IDENT\",[\"int\",false]]]],\
|
||||||
[\"tt_tok\",[null,[\"RPAREN\",[]]]]]]],\
|
[\"tt_tok\",[null,[\"RPAREN\",[]]]]\
|
||||||
[\"tt_delim\",[[[\"tt_tok\",[null,[\"LBRACE\",[]]]],\
|
]\
|
||||||
|
]],\
|
||||||
|
[\"tt_delim\",[\
|
||||||
|
[\
|
||||||
|
[\"tt_tok\",[null,[\"LBRACE\",[]]]],\
|
||||||
[\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\
|
[\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\
|
||||||
[\"tt_tok\",[null,[\"SEMI\",[]]]],\
|
[\"tt_tok\",[null,[\"SEMI\",[]]]],\
|
||||||
[\"tt_tok\",[null,[\"RBRACE\",[]]]]]]]]"
|
[\"tt_tok\",[null,[\"RBRACE\",[]]]]\
|
||||||
|
]\
|
||||||
|
]]\
|
||||||
|
]"
|
||||||
);
|
);
|
||||||
let ast1 = new_parser_from_tts(new_parse_sess(None),~[],tts)
|
let ast1 = new_parser_from_tts(new_parse_sess(None),~[],tts)
|
||||||
.parse_item(~[]);
|
.parse_item(~[]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue