summaryrefslogtreecommitdiff
path: root/tests/dot.rs
diff options
context:
space:
mode:
authorseancarroll <seanc28@gmail.com>2021-01-16 14:59:07 -0600
committerseancarroll <seanc28@gmail.com>2021-01-16 14:59:07 -0600
commite33b0b90e3a683a6c0431a50a8eb293aa3c3e326 (patch)
treef2bd38b181467fdcb2f825b146c45252bcac9ff7 /tests/dot.rs
parent859d57e497c726ef39f283e49387d43aa474d7ac (diff)
downloaddotavious-e33b0b90e3a683a6c0431a50a8eb293aa3c3e326.zip
Remove Attribute Statement Structs for IndexMap
I didnt think we were getting a ton of benefit from the AttributeStatement abstraction so I replaced it with IndexMap which the attribute statement impl were using internally. While the DOT language docs (https://graphviz.org/doc/info/lang.html) do call out attr_stmt as part of the language definition the overhead of the related traits, impl, structs, etc felt a bit heavy. In particular, supporting the ability to create them as part of a build as well as allowing users to add to them via other bulid fns was a bit awkward. For now I think removing the abstraction makes sense and provides for a simpler implementation. Can revisit this down the road if other requirements come up that perhaps warrant the addittional code.
Diffstat (limited to 'tests/dot.rs')
-rw-r--r--tests/dot.rs80
1 files changed, 79 insertions, 1 deletions
diff --git a/tests/dot.rs b/tests/dot.rs
index 526ff83..c4d31ba 100644
--- a/tests/dot.rs
+++ b/tests/dot.rs
@@ -1,5 +1,5 @@
use dotavious::attributes::{
- AttributeText, Color, CompassPoint, EdgeAttributes, EdgeStyle,
+ AttributeText, AttributeType, Color, CompassPoint, EdgeAttributes, EdgeStyle,
GraphAttributeStatementBuilder, GraphAttributes, GraphStyle, NodeAttributes,
NodeStyle, PortPosition, RankDir, Shape,
};
@@ -298,6 +298,84 @@ fn port_position_attribute() {
#[test]
fn graph_attributes() {
+ let g = GraphBuilder::new_directed(Some("graph_attributes".to_string()))
+ .add_attribute(
+ AttributeType::Graph,
+ "rankdir".to_string(),
+ AttributeText::from(RankDir::LeftRight),
+ )
+ .add_attribute(
+ AttributeType::Node,
+ "style".to_string(),
+ AttributeText::from(NodeStyle::Filled),
+ )
+ .add_attribute(
+ AttributeType::Edge,
+ "color".to_string(),
+ AttributeText::from(Color::Named("red")),
+ )
+ .build();
+
+ let r = test_input(g);
+
+ assert_eq!(
+ r.unwrap(),
+ r#"digraph graph_attributes {
+ graph [rankdir=LR];
+ node [style=filled];
+ edge [color="red"];
+}
+"#
+ );
+}
+
+#[test]
+fn graph_attributes_extend() {
+ let g = GraphBuilder::new_directed(Some("graph_attributes".to_string()))
+ .extend_with_attributes(
+ AttributeType::Graph,
+ [(
+ "rankdir".to_string(),
+ AttributeText::from(RankDir::LeftRight),
+ )]
+ .iter()
+ .cloned()
+ .collect(),
+ )
+ .extend_with_attributes(
+ AttributeType::Node,
+ [("style".to_string(), AttributeText::from(NodeStyle::Filled))]
+ .iter()
+ .cloned()
+ .collect(),
+ )
+ .extend_with_attributes(
+ AttributeType::Edge,
+ [(
+ "color".to_string(),
+ AttributeText::from(Color::Named("red")),
+ )]
+ .iter()
+ .cloned()
+ .collect(),
+ )
+ .build();
+
+ let r = test_input(g);
+
+ assert_eq!(
+ r.unwrap(),
+ r#"digraph graph_attributes {
+ graph [rankdir=LR];
+ node [style=filled];
+ edge [color="red"];
+}
+"#
+ );
+}
+
+#[test]
+fn graph_attributes_statement_builders() {
let graph_attributes = GraphAttributeStatementBuilder::new()
.rank_dir(RankDir::LeftRight)
.build();