diff --git a/src/lib.rs b/src/lib.rs index 0d43c51..760bda8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,6 +215,7 @@ where mod tests { use super::*; use std::assert_matches::assert_matches; + use std::collections::HashMap; #[test] fn test_parsing() { @@ -273,15 +274,24 @@ mod tests { ::= "{" [] {"," }* "}" ::= ":" */ + #[derive(Debug, Clone)] + enum JsonValue { + Null, + Bool(bool), + Str(String), + Num(f64), + Array(Vec), + Object(HashMap), + } #[test] fn parse_json() { - let json_null = literal("null"); - let json_true = literal("true"); - let json_false = literal("false"); + let json_null = literal("null").to(JsonValue::Null); + let json_true = literal("true").to(JsonValue::Bool(true)); + let json_false = literal("false").to(JsonValue::Bool(false)); let json_value = choice(json_null, choice(json_true, json_false)); - assert_matches!(json_value.parse("true"), Ok(("true", ""))); + assert_matches!(json_value.parse("true"), Ok((JsonValue::Bool(true), ""))); } }