afl: merge parse_balance target into parse

parse_balance is a superset of parse
This commit is contained in:
Noah Hellman 2023-04-30 19:58:23 +02:00
parent 2a3973674f
commit d19e4933c9
5 changed files with 7 additions and 17 deletions

View file

@ -72,7 +72,6 @@ jobs:
matrix:
target:
- parse
- parse_balance
- html
runs-on: ubuntu-latest
steps:

View file

@ -17,10 +17,6 @@ path = "src/main.rs"
name = "parse"
path = "src/parse.rs"
[[bin]]
name = "parse_balance"
path = "src/parse_balance.rs"
[[bin]]
name = "html"
path = "src/html.rs"

View file

@ -5,27 +5,26 @@ use html5ever::tendril::TendrilSink;
use html5ever::tokenizer;
use html5ever::tree_builder;
/// Perform sanity checks on events.
pub fn parse(data: &[u8]) {
if let Ok(s) = std::str::from_utf8(data) {
jotdown::Parser::new(s).last();
}
}
/// Ensure containers are always balanced, i.e. opened and closed in correct order.
pub fn parse_balance(data: &[u8]) {
if let Ok(s) = std::str::from_utf8(data) {
let mut open = Vec::new();
for event in jotdown::Parser::new(s) {
match event {
jotdown::Event::Start(c, ..) => open.push(c.clone()),
jotdown::Event::End(c) => assert_eq!(open.pop().unwrap(), c),
jotdown::Event::End(c) => {
// closes correct event
assert_eq!(open.pop().unwrap(), c);
}
_ => {}
}
}
// no missing close
assert_eq!(open, &[]);
}
}
/// Validate rendered html output.
pub fn html(data: &[u8]) {
if data.iter().any(|i| *i == 0) {
return;

View file

@ -8,7 +8,6 @@ fn main() {
let f = match target.as_str() {
"parse" => jotdown_afl::parse,
"parse_balance" => jotdown_afl::parse_balance,
"html" => jotdown_afl::html,
_ => panic!("unknown target '{}'", target),
};

View file

@ -1,3 +0,0 @@
fn main() {
afl::fuzz!(|data: &[u8]| { jotdown_afl::parse_balance(data) });
}