summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseancarroll <seanc28@gmail.com>2020-12-30 23:46:37 -0600
committerseancarroll <seanc28@gmail.com>2020-12-30 23:46:37 -0600
commitdbcab698b3cbaeb63e0758e91c2ccb7af9ecf90f (patch)
tree02cee7cc70201b5820c48cd891e2f16777851817
parentb18f21b6c0105d050d14dd6afbb8a400db116677 (diff)
downloaddotavious-dbcab698b3cbaeb63e0758e91c2ccb7af9ecf90f.zip
alter dot rendering to fix issue when graph id not provided
-rw-r--r--src/lib.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 533283d..46c99af 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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);