#![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"
));
let sample2 = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/resources/test/jsonfuzzsample2.json"
));
const ERROR: &str = "call limit reached";
pest::set_call_limit(Some(5_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);
let s2 = json::JsonParser::parse(json::Rule::json, sample2);
assert!(s2.is_err());
assert_eq!(s2.unwrap_err().variant.message(), ERROR);
}
}