Start json test

This commit is contained in:
Greg Shuflin 2022-10-16 01:36:20 -07:00
parent 8002b83a86
commit 22d0aa73de
1 changed files with 20 additions and 0 deletions

View File

@ -258,4 +258,24 @@ mod tests {
let p = choice(literal("gnostika").to(1), one_or_more(literal(" ")).to(2));
assert_eq!(p.parse("gnostika twentynine"), Ok((1, " twentynine")));
}
/*
* JSON BNF
* <JSON> ::= <value>
<value> ::= <object> | <array> | <boolean> | <string> | <number> | <null>
<array> ::= "[" [<value>] {"," <value>}* "]"
<object> ::= "{" [<property>] {"," <property>}* "}"
<property> ::= <string> ":" <value>
*/
#[test]
fn parse_json() {
let json_null = literal("null");
let json_true = literal("true");
let json_false = literal("false");
let json_value = choice(json_null, choice(json_true, json_false));
assert_matches!(json_value.parse("true"), Ok(("true", "")));
}
}