1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
|
extern crate json;
mod json_checker_fail {
use super::json::parse;
#[test]
fn unclosed_array() {
assert!(parse(r#"["Unclosed array""#).is_err());
}
#[test]
fn unquoted_key() {
assert!(parse(r#"{unquoted_key: "keys must be quoted"}"#).is_err());
}
#[test]
fn extra_comma_arr() {
assert!(parse(r#"["extra comma",]"#).is_err());
}
#[test]
fn double_extra_comma() {
assert!(parse(r#"["double extra comma",,]"#).is_err());
}
#[test]
fn missing_value() {
assert!(parse(r#"[ , "<-- missing value"]"#).is_err());
}
#[test]
fn comma_after_close() {
assert!(parse(r#"["Comma after the close"],"#).is_err());
}
#[test]
fn extra_close() {
assert!(parse(r#"["Extra close"]]"#).is_err());
}
#[test]
fn extra_comma_obj() {
assert!(parse(r#"{"Extra comma": true,}"#).is_err());
}
#[test]
fn extra_value_after_close() {
assert!(parse(r#"{"Extra value after close": true} "misplaced quoted value""#).is_err());
}
#[test]
fn illegal_expression() {
assert!(parse(r#"{"Illegal expression": 1 + 2}"#).is_err());
}
#[test]
fn illegal_invocation() {
assert!(parse(r#"{"Illegal invocation": alert()}"#).is_err());
}
#[test]
fn numbers_cannot_have_leading_zeroes() {
assert!(parse(r#"{"Numbers cannot have leading zeroes": 013}"#).is_err());
}
#[test]
fn numbers_cannot_be_hex() {
assert!(parse(r#"{"Numbers cannot be hex": 0x14}"#).is_err());
}
#[test]
fn illegal_backslash_escape() {
assert!(parse(r#"["Illegal backslash escape: \x15"]"#).is_err());
}
#[test]
fn naked() {
assert!(parse(r#"[\naked]"#).is_err());
}
#[test]
fn illegal_backslash_escape_2() {
assert!(parse(r#"["Illegal backslash escape: \017"]"#).is_err());
}
#[test]
fn missing_colon() {
assert!(parse(r#"{"Missing colon" null}"#).is_err());
}
#[test]
fn double_colon() {
assert!(parse(r#"{"Double colon":: null}"#).is_err());
}
#[test]
fn comma_instead_of_colon() {
assert!(parse(r#"{"Comma instead of colon", null}"#).is_err());
}
#[test]
fn colon_instead_of_comma() {
assert!(parse(r#"["Colon instead of comma": false]"#).is_err());
}
#[test]
fn bad_value() {
assert!(parse(r#"["Bad value", truth]"#).is_err());
}
#[test]
fn single_quote() {
assert!(parse(r#"['single quote']"#).is_err());
}
#[test]
fn tab_character_in_string() {
assert!(parse("[\"\ttab\tcharacter\tin\tstring\t\"]").is_err());
}
#[test]
fn tab_character_in_string_esc() {
assert!(parse("[\"tab\\\tcharacter\\\tin\\\tstring\\\t\"]").is_err());
}
#[test]
fn line_break() {
assert!(parse("[\"line\nbreak\"]").is_err());
}
#[test]
fn line_break_escaped() {
assert!(parse("[\"line\\\nbreak\"]").is_err());
}
#[test]
fn no_exponent() {
assert!(parse(r#"[0e]"#).is_err());
}
#[test]
fn no_exponent_plus() {
assert!(parse(r#"[0e+]"#).is_err());
}
#[test]
fn exponent_both_signs() {
assert!(parse(r#"[0e+-1]"#).is_err());
}
#[test]
fn comma_instead_of_closing_brace() {
assert!(parse(r#"{"Comma instead if closing brace": true,"#).is_err());
}
#[test]
fn missmatch() {
assert!(parse(r#"["mismatch"}"#).is_err());
}
}
mod json_checker_pass {
use super::json::parse;
#[test]
fn pass_1() {
parse(r##"
[
"JSON Test Pattern pass1",
{"object with 1 member":["array with 1 element"]},
{},
[],
-42,
true,
false,
null,
{
"integer": 1234567890,
"real": -9876.543210,
"e": 0.123456789e-12,
"E": 1.234567890E+34,
"": 23456789012E66,
"zero": 0,
"one": 1,
"space": " ",
"quote": "\"",
"backslash": "\\",
"controls": "\b\f\n\r\t",
"slash": "/ & \/",
"alpha": "abcdefghijklmnopqrstuvwyz",
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
"digit": "0123456789",
"0123456789": "digit",
"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
"true": true,
"false": false,
"null": null,
"array":[ ],
"object":{ },
"address": "50 St. James Street",
"url": "http://www.JSON.org/",
"comment": "// /* <!-- --",
"# -- --> */": " ",
" s p a c e d " :[1,2 , 3
,
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
"jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
"quotes": "" \u0022 %22 0x22 034 "",
"\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
: "A key can be any string"
},
0.5 ,98.6
,
99.44
,
1066,
1e1,
0.1e1,
1e-1,
1e00,2e+00,2e-00
,"rosebud"]
"##).unwrap();
assert!(true);
}
#[test]
fn pass_2() {
parse(r#"[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]"#).unwrap();
assert!(true);
}
#[test]
fn pass_3() {
parse(r#"
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
"In this test": "It is an object."
}
}
"#).unwrap();
assert!(true);
}
}
|