1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
extern crate pom;
mod dot;
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() {
let files = vec![
("src/test_fixtures/basic.1.dot", basic_1()),
("src/test_fixtures/digraph.dot", digraph()),
];
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),
}
}
}
}
}