polka 0.1.2

A dot language parser for Rust; based on Parser Expression Grammar (PEG) using the excellent pest crate as the underpinning.
Documentation
extern crate pom;

pub mod dot;
pub mod parser;
mod test_fixtures;

use dot::Graph;
use parser::graph::graph;

pub fn parse(input: String) -> Result<Graph, String> {
  let i: Vec<char> = input.chars().collect();
  let g = graph().parse(&i).map_err(|e| e.to_string());
  g
}

#[cfg(test)]
mod tests {
  mod parse {
    use super::super::parse;
    use crate::test_fixtures::{basic_1, digraph};

    use pretty_assertions::assert_eq;
    use std::fs;

    fn read_file(name: &str) -> String {
      fs::read_to_string(name).unwrap_or_else(|_| panic!("Cannot read file: {}", name))
    }

    #[test]
    fn known_examples_verify() {
      let files = vec![
        ("src/test_fixtures/basic.1.dot", basic_1()),
        // "src/test_fixtures/basic.2.dot",
        ("src/test_fixtures/digraph.dot", digraph()),
        // "src/test_fixtures/digrpah.labels.dot",
        // "src/test_fixtures/grouped.dot",
        // "src/test_fixtures/large.dot",
        // "src/test_fixtures/showing.path.2.dot",
        // "src/test_fixtures/showing.path.dot",
        // "src/test_fixtures/subgraph.2.dot",
        // "src/test_fixtures/subgraph.dot",
        // "src/test_fixtures/with_extended_ascii.dot",
        // "src/test_fixtures/ports.dot",
      ];

      for (file, res) in files {
        let input = read_file(file);
        match parse(input) {
          Ok(r) => assert_eq!(r, res),
          Err(e) => panic!("Should have passed. Failed instead with {:?}", e),
        }
      }
    }

    #[test]
    fn known_examples_parse() {
      let files = vec![
        "src/test_fixtures/basic.1.dot",
        "src/test_fixtures/basic.2.dot",
        "src/test_fixtures/digraph.dot",
        "src/test_fixtures/digrpah.labels.dot",
        // "src/test_fixtures/grouped.dot",
        "src/test_fixtures/large.dot",
        // "src/test_fixtures/showing.path.2.dot",
        // "src/test_fixtures/showing.path.dot",
        // "src/test_fixtures/subgraph.2.dot",
        // "src/test_fixtures/subgraph.dot",
        // "src/test_fixtures/with_extended_ascii.dot",
        "src/test_fixtures/ports.dot",
      ];

      for file in files {
        let input = read_file(file);
        match parse(input) {
          Ok(r) => (),
          Err(e) => panic!(
            "Should have passed. Failed instead on {:?} with {:?}",
            &file, e
          ),
        }
      }
    }

    // #[test]
    // fn snowflake() {
    //   let file = "src/test_fixtures/digrpah.labels.dot";
    //   let input = read_file(file);
    //   println!("{:?}", parse(input))
    // }
  }
}