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
#![doc(
html_root_url = "https://docs.rs/pest_grammars",
html_logo_url = "https://raw.githubusercontent.com/pest-parser/pest/master/pest-logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/pest-parser/pest/master/pest-logo.svg"
)]
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
#[macro_use]
extern crate pest_derive;
pub use pest::Parser;
#[allow(missing_docs)]
pub mod http {
#[derive(Parser)]
#[grammar = "grammars/http.pest"]
pub struct HttpParser;
}
#[allow(missing_docs)]
pub mod json {
#[derive(Parser)]
#[grammar = "grammars/json.pest"]
pub struct JsonParser;
}
#[allow(missing_docs)]
pub mod toml {
#[derive(Parser)]
#[grammar = "grammars/toml.pest"]
pub struct TomlParser;
}
#[cfg(test)]
mod tests {
use std::convert::TryInto;
use pest::Parser;
use crate::{json, toml};
fn test_toml_deep_nesting(input: &str) {
const ERROR: &str = "call limit reached";
pest::set_call_limit(Some(5_000usize.try_into().unwrap()));
let s = toml::TomlParser::parse(toml::Rule::toml, input);
assert!(s.is_err());
assert_eq!(s.unwrap_err().variant.message(), ERROR);
}
#[test]
fn toml_handles_deep_nesting() {
let sample1 = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/resources/test/tomlfuzzsample1.toml"
));
test_toml_deep_nesting(sample1);
}
#[test]
#[ignore = "this sometimes crashes in the debug mode"]
fn toml_handles_deep_nesting_unstable() {
let sample2 = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/resources/test/tomlfuzzsample2.toml"
));
test_toml_deep_nesting(sample2);
}
#[test]
fn json_handles_deep_nesting() {
let sample1 = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/resources/test/jsonfuzzsample1.json"
));
const ERROR: &str = "call limit reached";
pest::set_call_limit(Some(45_000usize.try_into().unwrap()));
let s1 = json::JsonParser::parse(json::Rule::json, sample1);
assert!(s1.is_err());
assert_eq!(s1.unwrap_err().variant.message(), ERROR);
}
}