From daab699f1f74bc96678dd41853701c3b8fdf5ab1 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 4 Dec 2022 00:22:33 -0800 Subject: [PATCH] Proptest: doesn't crash --- tests/json_parser.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/json_parser.rs b/tests/json_parser.rs index 0b598f7..25b36e3 100644 --- a/tests/json_parser.rs +++ b/tests/json_parser.rs @@ -4,6 +4,15 @@ use parser_combinator::primitives::{any_char, literal, literal_char, one_of, pre use parser_combinator::sequence::seq; use parser_combinator::Parser; +use proptest::prelude::*; + +proptest! { + #[test] + fn doesnt_crash(s in "\\PC*") { + let _output = json_object().parse(&s); + } +} + #[test] fn test_parsing() { let output = literal("a")("a yolo"); @@ -41,7 +50,7 @@ fn json_bool<'a>() -> impl JsonParser<'a, JsonValue> { )) } -fn json_number() -> impl JsonParser<'static, JsonValue> { +fn json_number<'a>() -> impl JsonParser<'a, JsonValue> { let digit = || one_of("1234567890"); let digits = || repeated(digit()).at_least(1); @@ -74,7 +83,7 @@ fn json_number() -> impl JsonParser<'static, JsonValue> { }) } -fn json_string_raw() -> impl JsonParser<'static, String> { +fn json_string_raw<'a>() -> impl JsonParser<'a, String> { seq(( literal_char('"'), repeated(pred(any_char, |ch| *ch != '"')), @@ -83,11 +92,11 @@ fn json_string_raw() -> impl JsonParser<'static, String> { .map(|(_, s, _)| s.iter().cloned().collect::()) } -fn json_string() -> impl JsonParser<'static, JsonValue> { +fn json_string<'a>() -> impl JsonParser<'a, JsonValue> { json_string_raw().map(JsonValue::Str) } -fn whitespace() -> impl JsonParser<'static, ()> { +fn whitespace<'a>() -> impl JsonParser<'a, ()> { repeated(choice(( literal_char('\t'), literal_char('\n'), @@ -96,7 +105,7 @@ fn whitespace() -> impl JsonParser<'static, ()> { .to(()) } -fn json_array() -> impl JsonParser<'static, JsonValue> { +fn json_array<'a>() -> impl JsonParser<'a, JsonValue> { move |input| { let val = json_value().surrounded_by(whitespace()); @@ -108,7 +117,7 @@ fn json_array() -> impl JsonParser<'static, JsonValue> { } } -fn json_object() -> impl JsonParser<'static, JsonValue> { +fn json_object<'a>() -> impl JsonParser<'a, JsonValue> { move |input| { let kv = json_string_raw() .surrounded_by(whitespace()) @@ -123,7 +132,7 @@ fn json_object() -> impl JsonParser<'static, JsonValue> { } } -fn json_value() -> impl JsonParser<'static, JsonValue> { +fn json_value<'a>() -> impl JsonParser<'a, JsonValue> { choice(( json_null(), json_bool(),