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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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/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),
}
}
}
#[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/large.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
),
}
}
}
}
}