Proptest: doesn't crash
This commit is contained in:
parent
50ca820cfe
commit
daab699f1f
@ -4,6 +4,15 @@ use parser_combinator::primitives::{any_char, literal, literal_char, one_of, pre
|
|||||||
use parser_combinator::sequence::seq;
|
use parser_combinator::sequence::seq;
|
||||||
use parser_combinator::Parser;
|
use parser_combinator::Parser;
|
||||||
|
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
#[test]
|
||||||
|
fn doesnt_crash(s in "\\PC*") {
|
||||||
|
let _output = json_object().parse(&s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parsing() {
|
fn test_parsing() {
|
||||||
let output = literal("a")("a yolo");
|
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 digit = || one_of("1234567890");
|
||||||
let digits = || repeated(digit()).at_least(1);
|
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((
|
seq((
|
||||||
literal_char('"'),
|
literal_char('"'),
|
||||||
repeated(pred(any_char, |ch| *ch != '"')),
|
repeated(pred(any_char, |ch| *ch != '"')),
|
||||||
@ -83,11 +92,11 @@ fn json_string_raw() -> impl JsonParser<'static, String> {
|
|||||||
.map(|(_, s, _)| s.iter().cloned().collect::<String>())
|
.map(|(_, s, _)| s.iter().cloned().collect::<String>())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_string() -> impl JsonParser<'static, JsonValue> {
|
fn json_string<'a>() -> impl JsonParser<'a, JsonValue> {
|
||||||
json_string_raw().map(JsonValue::Str)
|
json_string_raw().map(JsonValue::Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn whitespace() -> impl JsonParser<'static, ()> {
|
fn whitespace<'a>() -> impl JsonParser<'a, ()> {
|
||||||
repeated(choice((
|
repeated(choice((
|
||||||
literal_char('\t'),
|
literal_char('\t'),
|
||||||
literal_char('\n'),
|
literal_char('\n'),
|
||||||
@ -96,7 +105,7 @@ fn whitespace() -> impl JsonParser<'static, ()> {
|
|||||||
.to(())
|
.to(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_array() -> impl JsonParser<'static, JsonValue> {
|
fn json_array<'a>() -> impl JsonParser<'a, JsonValue> {
|
||||||
move |input| {
|
move |input| {
|
||||||
let val = json_value().surrounded_by(whitespace());
|
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| {
|
move |input| {
|
||||||
let kv = json_string_raw()
|
let kv = json_string_raw()
|
||||||
.surrounded_by(whitespace())
|
.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((
|
choice((
|
||||||
json_null(),
|
json_null(),
|
||||||
json_bool(),
|
json_bool(),
|
||||||
|
Loading…
Reference in New Issue
Block a user