diff options
author | seancarroll <seanc28@gmail.com> | 2020-12-30 23:46:37 -0600 |
---|---|---|
committer | seancarroll <seanc28@gmail.com> | 2020-12-30 23:46:37 -0600 |
commit | dbcab698b3cbaeb63e0758e91c2ccb7af9ecf90f (patch) | |
tree | 02cee7cc70201b5820c48cd891e2f16777851817 | |
parent | b18f21b6c0105d050d14dd6afbb8a400db116677 (diff) | |
download | dotavious-dbcab698b3cbaeb63e0758e91c2ccb7af9ecf90f.zip |
alter dot rendering to fix issue when graph id not provided
-rw-r--r-- | src/lib.rs | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -212,11 +212,15 @@ impl<'a> Dot<'a> { writeln!(w, "// {}", comment)?; } - let strict = if self.graph.strict { "strict " } else { "" }; - let id = self.graph.id.as_deref().unwrap_or_default(); - let edge_op = self.graph.edge_op(); + let edge_op = &self.graph.edge_op(); + let strict = if self.graph.strict { "strict " } else { "" }; + write!(w, "{}{}", strict, &self.graph.graph_type())?; - writeln!(w, "{}{} {} {{", strict, &self.graph.graph_type(), id)?; + if let Some(id) = &self.graph.id { + write!(w, " {}", id)?; + } + + writeln!(w, " {{")?; if let Some(graph_attributes) = self.graph.graph_attributes { write!(w, "{}{}\n", INDENT, graph_attributes.to_dot_string())?; @@ -3239,6 +3243,19 @@ fn test_input(g: Graph) -> io::Result<String> // TODO: color test #[test] +fn empty_digraph_without_id() { + // TODO: support both String and &str + let g = GraphBuilder::new_directed(None).build(); + let r = test_input(g); + assert_eq!( + r.unwrap(), + r#"digraph { +} +"# + ); +} + +#[test] fn empty_digraph() { // TODO: support both String and &str let g = GraphBuilder::new_directed(Some("empty_graph".to_string())).build(); @@ -3252,7 +3269,7 @@ fn empty_digraph() { } #[test] -fn empty_graph() { +fn empty_undirected_graph() { // TODO: support both String and &str let g = GraphBuilder::new_undirected(Some("empty_graph".to_string())).build(); let r = test_input(g); |