Skip to content

Commit

Permalink
feature: added http request grammar (#726)
Browse files Browse the repository at this point in the history
plus tests, benchmark and a fuzzing target

based on #372 by @adamAndMath

Closes #210

Co-authored-by: Adam <adam.and.math@gmail.com>

Co-authored-by: Tomas Tauber <me@tomtau.be>
Co-authored-by: Adam <adam.and.math@gmail.com>
  • Loading branch information
3 people committed Oct 25, 2022
1 parent d5fa6eb commit 683a7e7
Show file tree
Hide file tree
Showing 10 changed files with 639 additions and 2 deletions.
5 changes: 3 additions & 2 deletions FUZZING.md
Expand Up @@ -21,11 +21,12 @@ There is a single fuzzing target for this crate that interacts with

### `pest_grammars`

- `http`
- `toml`
- `json`

There are two fuzzing targets for this crate: one tests the json grammar in the
`json` module and the other tests the toml grammar in the `toml` module. They
There are three fuzzing targets for this crate: one tests the http request grammar in the `http` module, one tests the json grammar in the
`json` module and the last one tests the toml grammar in the `toml` module. They
interact directly with the `pest::Parser::parse` function provided by derived
on the respective Parsers in each module.

Expand Down
4 changes: 4 additions & 0 deletions grammars/Cargo.toml
Expand Up @@ -22,4 +22,8 @@ criterion = "0.3"

[[bench]]
name = "json"
harness = false

[[bench]]
name = "http"
harness = false
22 changes: 22 additions & 0 deletions grammars/benches/http.rs
@@ -0,0 +1,22 @@
use criterion::{criterion_group, criterion_main, Criterion};

use std::fs::File;
use std::io::Read;

use pest::Parser;

use pest_grammars::http::*;

fn criterion_benchmark(c: &mut Criterion) {
let mut file = File::open("benches/requests.http").unwrap();
let mut data = String::new();

file.read_to_string(&mut data).unwrap();

c.bench_function("http parser", |b| {
b.iter(|| HttpParser::parse(Rule::http, &data).unwrap())
});
}

criterion_group!(benches, criterion_benchmark,);
criterion_main!(benches);

0 comments on commit 683a7e7

Please sign in to comment.