afl: merge parse_balance target into parse
parse_balance is a superset of parse
This commit is contained in:
		
					parent
					
						
							
								2a3973674f
							
						
					
				
			
			
				commit
				
					
						d19e4933c9
					
				
			
		
					 5 changed files with 7 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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),
 | 
			
		||||
    };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +0,0 @@
 | 
			
		|||
fn main() {
 | 
			
		||||
    afl::fuzz!(|data: &[u8]| { jotdown_afl::parse_balance(data) });
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue