libstd: Move std tests into libstd
This commit is contained in:
parent
17bf4b0e1b
commit
6e27b27cf8
51 changed files with 2926 additions and 3032 deletions
|
@ -268,3 +268,58 @@ fn from_str(s: str) -> option::t<json> {
|
|||
let (j, _) = from_str_helper(s);
|
||||
j
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_from_str_null() {
|
||||
assert(from_str("null") == some(null));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str_num() {
|
||||
assert(from_str("3") == some(num(3f)));
|
||||
assert(from_str("3.1") == some(num(3.1f)));
|
||||
assert(from_str("-1.2") == some(num(-1.2f)));
|
||||
assert(from_str(".4") == some(num(0.4f)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str_str() {
|
||||
assert(from_str("\"foo\"") == some(string("foo")));
|
||||
assert(from_str("\"\\\"\"") == some(string("\"")));
|
||||
assert(from_str("\"lol") == none);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str_bool() {
|
||||
assert(from_str("true") == some(boolean(true)));
|
||||
assert(from_str("false") == some(boolean(false)));
|
||||
assert(from_str("truz") == none);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str_list() {
|
||||
assert(from_str("[]") == some(list(@[])));
|
||||
assert(from_str("[true]") == some(list(@[boolean(true)])));
|
||||
assert(from_str("[null]") == some(list(@[null])));
|
||||
assert(from_str("[3, 1]") == some(list(@[num(3f), num(1f)])));
|
||||
assert(from_str("[2, [4, 1]]") ==
|
||||
some(list(@[num(2f), list(@[num(4f), num(1f)])])));
|
||||
assert(from_str("[2, ]") == none);
|
||||
assert(from_str("[5, ") == none);
|
||||
assert(from_str("[6 7]") == none);
|
||||
assert(from_str("[3") == none);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str_dict() {
|
||||
assert(from_str("{}") != none);
|
||||
assert(from_str("{\"a\": 3}") != none);
|
||||
assert(from_str("{\"a\": null}") != none);
|
||||
assert(from_str("{\"a\": }") == none);
|
||||
assert(from_str("{\"a\" }") == none);
|
||||
assert(from_str("{\"a\"") == none);
|
||||
assert(from_str("{") == none);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue