diff --git a/Graph_test.go b/Graph_test.go index 2122272..45bdae3 100644 --- a/Graph_test.go +++ b/Graph_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/wwmoraes/dot/attributes" + "github.com/wwmoraes/dot/constants" "github.com/wwmoraes/dot/dottest" ) @@ -22,7 +23,7 @@ func TestGraphBehavior(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - graph.Node("n1").Edge(graph.Node("n2")).SetAttributeString(attributes.KeyLabel, "uses") + graph.Node("n1").Edge(graph.Node("n2")).SetAttributeString(constants.KeyLabel, "uses") expected := `digraph {"n1";"n2";"n1"->"n2"[label="uses"];}` @@ -36,7 +37,7 @@ func TestGraphBehavior(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - graph.Node("n1").Edge(graph.Node("n2")).SetAttributeString(attributes.KeyLabel, "uses") + graph.Node("n1").Edge(graph.Node("n2")).SetAttributeString(constants.KeyLabel, "uses") expected := `digraph {"n1";"n2";"n1"->"n2"[label="uses"];}` @@ -50,7 +51,7 @@ func TestGraphBehavior(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - graph.Node("n1").Edge(graph.Node("n2")).SetAttributeString(attributes.KeyLabel, "uses") + graph.Node("n1").Edge(graph.Node("n2")).SetAttributeString(constants.KeyLabel, "uses") expected := `graph {"n1";"n2";"n1"--"n2"[label="uses"];}` @@ -245,7 +246,7 @@ func TestGraph_Initializers(t *testing.T) { t.Run("graph with node initializer", func(t *testing.T) { graph, err := NewGraph( WithNodeInitializer(func(nodeInstance Node) { - nodeInstance.SetAttributeString(attributes.KeyClass, "test-class") + nodeInstance.SetAttributeString(constants.KeyClass, "test-class") }), ) if err != nil { @@ -261,7 +262,7 @@ func TestGraph_Initializers(t *testing.T) { t.Run("graph with edge initializer", func(t *testing.T) { graph, err := NewGraph( WithEdgeInitializer(func(edgeInstance StyledEdge) { - edgeInstance.SetAttributeString(attributes.KeyClass, "test-class") + edgeInstance.SetAttributeString(constants.KeyClass, "test-class") }), ) if err != nil { @@ -651,8 +652,8 @@ func TestEmptyWithIDAndAttributes(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - di.SetAttribute(attributes.KeyStyle, attributes.NewString("filled")) - di.SetAttribute(attributes.KeyColor, attributes.NewString("lightgrey")) + di.SetAttribute(constants.KeyStyle, attributes.NewString("filled")) + di.SetAttribute(constants.KeyColor, attributes.NewString("lightgrey")) if got, want := dottest.MustGetFlattenSerializableString(t, di), `digraph {graph [color="lightgrey",style="filled"];}`; got != want { t.Errorf("got [\n%v\n] want [\n%v\n]", got, want) } @@ -664,7 +665,7 @@ func TestEmptyWithHTMLLabel(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - di.SetAttribute(attributes.KeyLabel, attributes.NewHTML("Hi")) + di.SetAttribute(constants.KeyLabel, attributes.NewHTML("Hi")) if got, want := dottest.MustGetFlattenSerializableString(t, di), `digraph {graph [label=<Hi>];}`; got != want { t.Errorf("got [\n%v\n] want [\n%v\n]", got, want) } @@ -676,7 +677,7 @@ func TestEmptyWithLiteralValueLabel(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - di.SetAttribute(attributes.KeyLabel, attributes.NewLiteral(`"left-justified text\l"`)) + di.SetAttribute(constants.KeyLabel, attributes.NewLiteral(`"left-justified text\l"`)) if got, want := dottest.MustGetFlattenSerializableString(t, di), `digraph {graph [label="left-justified text\l"];}`; got != want { t.Errorf("got [\n%v\n] want [\n%v\n]", got, want) } @@ -710,7 +711,7 @@ func TestTwoConnectedNodesAcrossSubgraphs(t *testing.T) { n2 := sub.Node("B") edge := di.Edge(n1, n2) - edge.SetAttributeString(attributes.KeyLabel, "cross-graph") + edge.SetAttributeString(constants.KeyLabel, "cross-graph") // test graph-level edge finding { @@ -777,11 +778,11 @@ func TestSubgraph(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - sub.SetAttributeString(attributes.KeyStyle, "filled") + sub.SetAttributeString(constants.KeyStyle, "filled") if got, want := dottest.MustGetFlattenSerializableString(t, di), fmt.Sprintf(`digraph {subgraph "%s" {graph [style="filled"];}}`, sub.ID()); got != want { t.Errorf("got [\n%v\n] want [\n%v\n]", got, want) } - sub.SetAttributeString(attributes.KeyLabel, "new-label") + sub.SetAttributeString(constants.KeyLabel, "new-label") if got, want := dottest.MustGetFlattenSerializableString(t, di), fmt.Sprintf(`digraph {subgraph "%s" {graph [label="new-label",style="filled"];}}`, sub.ID()); got != want { t.Errorf("got [\n%v\n] want [\n%v\n]", got, want) } @@ -839,8 +840,8 @@ func TestNode(t *testing.T) { node := graph.Node("") node.SetAttributesString(attributes.MapString{ - attributes.KeyLabel: "test", - attributes.KeyShape: "box", + constants.KeyLabel: "test", + constants.KeyShape: "box", }) if node.ID() == "" { @@ -874,7 +875,7 @@ func TestEdgeLabel(t *testing.T) { n1 := di.Node("e1") n2 := di.Node("e2") attr := attributes.NewAttributes() - attr.SetAttributeString(attributes.KeyLabel, "what") + attr.SetAttributeString(constants.KeyLabel, "what") n1.EdgeWithAttributes(n2, attr) if got, want := dottest.MustGetFlattenSerializableString(t, di), `digraph {"e1";"e2";"e1"->"e2"[label="what"];}`; got != want { t.Errorf("got [\n%v\n] want [\n%v\n]", got, want) @@ -913,7 +914,7 @@ func TestCluster(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - clusterA.SetAttributeString(attributes.KeyLabel, "Cluster A") + clusterA.SetAttributeString(constants.KeyLabel, "Cluster A") insideOne := clusterA.Node("one") insideTwo := clusterA.Node("two") clusterB, err := di.Subgraph( @@ -924,7 +925,7 @@ func TestCluster(t *testing.T) { t.Fatal("graph is nil, expected a valid instance") } - clusterB.SetAttributeString(attributes.KeyLabel, "Cluster B") + clusterB.SetAttributeString(constants.KeyLabel, "Cluster B") insideThree := clusterB.Node("three") insideFour := clusterB.Node("four") outside.Edge(insideFour).Edge(insideOne).Edge(insideTwo).Edge(insideThree).Edge(outside) @@ -941,7 +942,7 @@ func TestDeleteLabel(t *testing.T) { } n := g.Node("my-id") - n.DeleteAttribute(attributes.KeyLabel) + n.DeleteAttribute(constants.KeyLabel) if got, want := dottest.MustGetFlattenSerializableString(t, g), `digraph {"my-id";}`; got != want { t.Errorf("got [\n%v\n] want [\n%v\n]", got, want) } @@ -1039,7 +1040,7 @@ func TestLabelWithEscaping(t *testing.T) { } n := di.Node("without-linefeed") - n.SetAttribute(attributes.KeyLabel, attributes.NewLiteral(`"with \l linefeed"`)) + n.SetAttribute(constants.KeyLabel, attributes.NewLiteral(`"with \l linefeed"`)) if got, want := dottest.MustGetFlattenSerializableString(t, di), `digraph {"without-linefeed"[label="with \l linefeed"];}`; got != want { t.Errorf("got [\n%v\n] want [\n%v\n]", got, want) } @@ -1048,7 +1049,7 @@ func TestLabelWithEscaping(t *testing.T) { func TestGraphNodeInitializer(t *testing.T) { di, err := NewGraph( WithNodeInitializer(func(n Node) { - n.SetAttribute(attributes.KeyLabel, attributes.NewString("test")) + n.SetAttribute(constants.KeyLabel, attributes.NewString("test")) }), ) if err != nil { @@ -1056,7 +1057,7 @@ func TestGraphNodeInitializer(t *testing.T) { } n := di.Node("A") - gotAttr, gotOk := n.GetAttribute(attributes.KeyLabel) + gotAttr, gotOk := n.GetAttribute(constants.KeyLabel) if !gotOk { t.Error("attribute not found") } @@ -1068,7 +1069,7 @@ func TestGraphNodeInitializer(t *testing.T) { func TestGraphEdgeInitializer(t *testing.T) { di, err := NewGraph( WithEdgeInitializer(func(e StyledEdge) { - e.SetAttribute(attributes.KeyLabel, attributes.NewString("test")) + e.SetAttribute(constants.KeyLabel, attributes.NewString("test")) }), ) if err != nil { @@ -1076,7 +1077,7 @@ func TestGraphEdgeInitializer(t *testing.T) { } e := di.Node("A").Edge(di.Node("B")) - gotAttr, gotOk := e.GetAttribute(attributes.KeyLabel) + gotAttr, gotOk := e.GetAttribute(constants.KeyLabel) if !gotOk { t.Error("attribute not found") } diff --git a/attributes/Reader.go b/attributes/Reader.go index 1faa94c..71bf67b 100644 --- a/attributes/Reader.go +++ b/attributes/Reader.go @@ -2,14 +2,16 @@ package attributes import ( "fmt" + + "github.com/wwmoraes/dot/constants" ) // Reader is implemented by attribute-based values that allows reading them type Reader interface { // GetAttribute returns the attribute value or nil if unset - GetAttribute(key Key) (fmt.Stringer, bool) + GetAttribute(key constants.Key) (fmt.Stringer, bool) // GetAttributeString returns the attribute as string or an empty string if unset - GetAttributeString(key Key) string + GetAttributeString(key constants.Key) string // GetAttributes returns a copy of all attributes GetAttributes() Map // HasAttributes returns true if there's any attribute set diff --git a/attributes/Writer.go b/attributes/Writer.go index cf5024f..3849e5d 100644 --- a/attributes/Writer.go +++ b/attributes/Writer.go @@ -2,18 +2,20 @@ package attributes import ( "fmt" + + "github.com/wwmoraes/dot/constants" ) // Writer is implemented by attribute-based values that allows mutating them type Writer interface { // SetAttribute sets the value for the attribute Key - SetAttribute(key Key, value fmt.Stringer) + SetAttribute(key constants.Key, value fmt.Stringer) // SetAttributeString sets the string value for the attribute Key - SetAttributeString(key Key, value string) + SetAttributeString(key constants.Key, value string) // SetAttributeLiteral sets the literal value for the attribute Key - SetAttributeLiteral(key Key, value string) + SetAttributeLiteral(key constants.Key, value string) // SetAttributeHTML sets the HTML value for the attribute Key - SetAttributeHTML(key Key, value string) + SetAttributeHTML(key constants.Key, value string) // SetAttributes sets the value for multiple attributes SetAttributes(attributeMap Map) // SetAttributesString sets the string value for multiple attributes @@ -23,5 +25,5 @@ type Writer interface { // SetAttributesHTML sets the HTML value for multiple attributes SetAttributesHTML(attributeMap MapString) // DeleteAttribute unset the attribute Key - DeleteAttribute(key Key) + DeleteAttribute(key constants.Key) } diff --git a/attributes/attributes.go b/attributes/attributes.go index 882ff96..5ad1d65 100644 --- a/attributes/attributes.go +++ b/attributes/attributes.go @@ -5,13 +5,15 @@ import ( "io" "sort" "strings" + + "github.com/wwmoraes/dot/constants" ) // Map collection of dot component attributes -type Map map[Key]fmt.Stringer +type Map map[constants.Key]fmt.Stringer // MapString collection of dot component attributes as primitive strings -type MapString map[Key]string +type MapString map[constants.Key]string // Attributes dot component attributes data type Attributes struct { @@ -42,13 +44,13 @@ func (dotObjectData *Attributes) getAttributes() Map { } // GetAttribute returns the attribute value or nil if unset -func (dotObjectData *Attributes) GetAttribute(key Key) (fmt.Stringer, bool) { +func (dotObjectData *Attributes) GetAttribute(key constants.Key) (fmt.Stringer, bool) { attr, found := dotObjectData.attributes[key] return attr, found } // GetAttributeString returns the attribute as string or an empty string if unset -func (dotObjectData *Attributes) GetAttributeString(key Key) string { +func (dotObjectData *Attributes) GetAttributeString(key constants.Key) string { attr, ok := dotObjectData.GetAttribute(key) if !ok { @@ -68,22 +70,22 @@ func (dotObjectData *Attributes) GetAttributes() Map { } // SetAttribute sets the value for the attribute Key -func (dotObjectData *Attributes) SetAttribute(key Key, value fmt.Stringer) { +func (dotObjectData *Attributes) SetAttribute(key constants.Key, value fmt.Stringer) { dotObjectData.attributes[key] = value } // SetAttributeString sets the string value for the attribute Key -func (dotObjectData *Attributes) SetAttributeString(key Key, value string) { +func (dotObjectData *Attributes) SetAttributeString(key constants.Key, value string) { dotObjectData.attributes[key] = NewString(value) } // SetAttributeLiteral sets the literal value for the attribute Key -func (dotObjectData *Attributes) SetAttributeLiteral(key Key, value string) { +func (dotObjectData *Attributes) SetAttributeLiteral(key constants.Key, value string) { dotObjectData.attributes[key] = NewLiteral(value) } // SetAttributeHTML sets the HTML value for the attribute Key -func (dotObjectData *Attributes) SetAttributeHTML(key Key, value string) { +func (dotObjectData *Attributes) SetAttributeHTML(key constants.Key, value string) { dotObjectData.attributes[key] = NewHTML(value) } @@ -116,7 +118,7 @@ func (dotObjectData *Attributes) SetAttributesHTML(attributeMap MapString) { } // DeleteAttribute unset the attribute Key -func (dotObjectData *Attributes) DeleteAttribute(key Key) { +func (dotObjectData *Attributes) DeleteAttribute(key constants.Key) { delete(dotObjectData.attributes, key) } @@ -127,7 +129,7 @@ func (dotObjectData *Attributes) WriteTo(writer io.Writer) (n int64, err error) } // first collect keys - keys := []Key{} + keys := []constants.Key{} for k := range dotObjectData.attributes { keys = append(keys, k) } diff --git a/attributes/attributes_test.go b/attributes/attributes_test.go index 5ffe85b..db74bbb 100644 --- a/attributes/attributes_test.go +++ b/attributes/attributes_test.go @@ -4,17 +4,19 @@ import ( "reflect" "strings" "testing" + + "github.com/wwmoraes/dot/constants" ) func TestAttributes(t *testing.T) { t.Run("equal on attribute re-set with same value", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttribute(KeyLabel, NewString("test")) + attributes.SetAttribute(constants.KeyLabel, NewString("test")) got := attributes.GetAttributes() want := Map{ - KeyLabel: NewString("test"), + constants.KeyLabel: NewString("test"), } if !reflect.DeepEqual(got, want) { @@ -23,9 +25,9 @@ func TestAttributes(t *testing.T) { }) t.Run("get attribute previously set", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttribute(KeyLabel, NewString("test")) + attributes.SetAttribute(constants.KeyLabel, NewString("test")) - got, _ := attributes.GetAttribute(KeyLabel) + got, _ := attributes.GetAttribute(constants.KeyLabel) want := NewString("test") @@ -79,7 +81,7 @@ func TestAttributes_NewAttributesFrom(t *testing.T) { }) t.Run("copy attributes given on initialization", func(t *testing.T) { sourceAttributes := NewAttributes() - sourceAttributes.SetAttributeString(KeyLabel, "test-label") + sourceAttributes.SetAttributeString(constants.KeyLabel, "test-label") attributes := NewAttributesFrom(sourceAttributes) var gotStringBuilder strings.Builder @@ -106,14 +108,14 @@ func TestAttributes_GetAttributes(t *testing.T) { t.Run("does not mutate using GetAttributes copy map", func(t *testing.T) { attributes := NewAttributes() value := NewString("test") - attributes.SetAttribute(KeyLabel, value) + attributes.SetAttribute(constants.KeyLabel, value) indirectAttributes := attributes.GetAttributes() - indirectAttributes[KeyClass] = NewString("my-class") + indirectAttributes[constants.KeyClass] = NewString("my-classconstants.") got := attributes.GetAttributes() want := Map{ - KeyLabel: value, + constants.KeyLabel: value, } if !reflect.DeepEqual(got, want) { @@ -123,16 +125,16 @@ func TestAttributes_GetAttributes(t *testing.T) { t.Run("mutates using getAttributes map reference", func(t *testing.T) { attributes := NewAttributes() labelValue := NewString("test") - attributes.SetAttribute(KeyLabel, labelValue) + attributes.SetAttribute(constants.KeyLabel, labelValue) indirectAttributes := attributes.getAttributes() classValue := NewString("my-class") - indirectAttributes[KeyClass] = classValue + indirectAttributes[constants.KeyClass] = classValue got := attributes.GetAttributes() want := Map{ - KeyLabel: labelValue, - KeyClass: classValue, + constants.KeyLabel: labelValue, + constants.KeyClass: classValue, } if !reflect.DeepEqual(got, want) { @@ -141,9 +143,9 @@ func TestAttributes_GetAttributes(t *testing.T) { }) t.Run("get single attribute as string", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttribute(KeyLabel, NewHTML("html label")) + attributes.SetAttribute(constants.KeyLabel, NewHTML("html label")) - got := attributes.GetAttributeString(KeyLabel) + got := attributes.GetAttributeString(constants.KeyLabel) want := "html label" @@ -154,7 +156,7 @@ func TestAttributes_GetAttributes(t *testing.T) { t.Run("get single unset attribute as string", func(t *testing.T) { attributes := NewAttributes() - got := attributes.GetAttributeString(KeyLabel) + got := attributes.GetAttributeString(constants.KeyLabel) want := "" @@ -167,7 +169,7 @@ func TestAttributes_GetAttributes(t *testing.T) { func TestAttributes_WriteTo(t *testing.T) { t.Run("writes single string attribute without brackets", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttribute(KeyLabel, NewString("test")) + attributes.SetAttribute(constants.KeyLabel, NewString("test")) var gotStringBuilder strings.Builder _, err := attributes.WriteTo(&gotStringBuilder) @@ -184,7 +186,7 @@ func TestAttributes_WriteTo(t *testing.T) { }) t.Run("writes single string attribute with brackets", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttribute(KeyLabel, NewString("test")) + attributes.SetAttribute(constants.KeyLabel, NewString("test")) var gotStringBuilder strings.Builder _, err := attributes.WriteTo(&gotStringBuilder) @@ -201,7 +203,7 @@ func TestAttributes_WriteTo(t *testing.T) { }) t.Run("writes single HTML attribute without brackets", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttributeHTML(KeyLabel, "Hi") + attributes.SetAttributeHTML(constants.KeyLabel, "Hi") var gotStringBuilder strings.Builder _, err := attributes.WriteTo(&gotStringBuilder) @@ -218,7 +220,7 @@ func TestAttributes_WriteTo(t *testing.T) { }) t.Run("writes single HTML attribute with brackets", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttributeHTML(KeyLabel, "Hi") + attributes.SetAttributeHTML(constants.KeyLabel, "Hi") var gotStringBuilder strings.Builder _, err := attributes.WriteTo(&gotStringBuilder) @@ -235,7 +237,7 @@ func TestAttributes_WriteTo(t *testing.T) { }) t.Run("writes single Literal attribute without brackets", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttributeLiteral(KeyLabel, `"left text\l"`) + attributes.SetAttributeLiteral(constants.KeyLabel, `"left text\l"`) var gotStringBuilder strings.Builder _, err := attributes.WriteTo(&gotStringBuilder) @@ -252,7 +254,7 @@ func TestAttributes_WriteTo(t *testing.T) { }) t.Run("writes single Literal attribute with brackets", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttributeLiteral(KeyLabel, `"left text\l"`) + attributes.SetAttributeLiteral(constants.KeyLabel, `"left text\l"`) var gotStringBuilder strings.Builder _, err := attributes.WriteTo(&gotStringBuilder) @@ -270,8 +272,8 @@ func TestAttributes_WriteTo(t *testing.T) { t.Run("writes multi attributes without brackets", func(t *testing.T) { attributes := NewAttributes() attributes.SetAttributesString(MapString{ - KeyClass: "my-class", - KeyLabel: "my-label", + constants.KeyClass: "my-class", + constants.KeyLabel: "my-label", }) var gotStringBuilder strings.Builder @@ -290,8 +292,8 @@ func TestAttributes_WriteTo(t *testing.T) { t.Run("writes multi attributes with brackets", func(t *testing.T) { attributes := NewAttributes() attributes.SetAttributesString(MapString{ - KeyClass: "my-class", - KeyLabel: "my-label", + constants.KeyClass: "my-class", + constants.KeyLabel: "my-label", }) var gotStringBuilder strings.Builder @@ -312,10 +314,10 @@ func TestAttributes_WriteTo(t *testing.T) { func TestAttributes_SetAttribute(t *testing.T) { t.Run("set attribute using single attribute set methods", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttributeString(KeyClass, "my-class") - attributes.SetAttributeHTML(KeyLabel, "my-label") - attributes.SetAttributeLiteral(KeyXlabel, `"left text\l"`) - attributes.SetAttribute(KeyColor, NewString("black")) + attributes.SetAttributeString(constants.KeyClass, "my-class") + attributes.SetAttributeHTML(constants.KeyLabel, "my-label") + attributes.SetAttributeLiteral(constants.KeyXlabel, `"left text\l"`) + attributes.SetAttribute(constants.KeyColor, NewString("black")) var gotStringBuilder strings.Builder _, err := attributes.WriteTo(&gotStringBuilder) @@ -333,16 +335,16 @@ func TestAttributes_SetAttribute(t *testing.T) { t.Run("set attribute using multi attribute set methods", func(t *testing.T) { attributes := NewAttributes() attributes.SetAttributesString(MapString{ - KeyClass: "my-class", + constants.KeyClass: "my-class", }) attributes.SetAttributesHTML(MapString{ - KeyLabel: "my-label", + constants.KeyLabel: "my-label", }) attributes.SetAttributesLiteral(MapString{ - KeyXlabel: `"left text\l"`, + constants.KeyXlabel: `"left text\l"`, }) attributes.SetAttributes(Map{ - KeyColor: NewString("black"), + constants.KeyColor: NewString("black"), }) var gotStringBuilder strings.Builder @@ -363,7 +365,7 @@ func TestAttributes_SetAttribute(t *testing.T) { func TestAttributes_DeleteAttribute(t *testing.T) { t.Run("try to delete un-existent attribute", func(t *testing.T) { attributes := NewAttributes() - attributes.DeleteAttribute(KeyClass) + attributes.DeleteAttribute(constants.KeyClass) got := attributes.GetAttributes() @@ -375,8 +377,8 @@ func TestAttributes_DeleteAttribute(t *testing.T) { }) t.Run("delete a set attribute", func(t *testing.T) { attributes := NewAttributes() - attributes.SetAttribute(KeyLabel, NewString("test")) - attributes.DeleteAttribute(KeyLabel) + attributes.SetAttribute(constants.KeyLabel, NewString("test")) + attributes.DeleteAttribute(constants.KeyLabel) got := attributes.GetAttributes() diff --git a/attributes/ClusterModeConstants.go b/constants/ClusterMode.go similarity index 97% rename from attributes/ClusterModeConstants.go rename to constants/ClusterMode.go index 9b101be..1a22599 100644 --- a/attributes/ClusterModeConstants.go +++ b/constants/ClusterMode.go @@ -1,4 +1,4 @@ -package attributes +package constants // ClusterMode mode used for handling clusters type ClusterMode string diff --git a/attributes/DirTypeConstants.go b/constants/DirType.go similarity index 95% rename from attributes/DirTypeConstants.go rename to constants/DirType.go index 8a85994..da70d5b 100644 --- a/attributes/DirTypeConstants.go +++ b/constants/DirType.go @@ -1,4 +1,4 @@ -package attributes +package constants // DirType type for drawing arrowheads type DirType string diff --git a/attributes/EdgeTypeConstants.go b/constants/EdgeType.go similarity index 93% rename from attributes/EdgeTypeConstants.go rename to constants/EdgeType.go index 56b883d..e07cf89 100644 --- a/attributes/EdgeTypeConstants.go +++ b/constants/EdgeType.go @@ -1,4 +1,4 @@ -package attributes +package constants // EdgeType is a supported edge notation type EdgeType string diff --git a/attributes/keysConstants.go b/constants/Key.go similarity index 99% rename from attributes/keysConstants.go rename to constants/Key.go index e553711..002bac3 100644 --- a/attributes/keysConstants.go +++ b/constants/Key.go @@ -1,4 +1,4 @@ -package attributes +package constants // Key attribute key type type Key string diff --git a/attributes/ArrowTypeConstants.go b/constants/PrimitiveShape.go similarity index 98% rename from attributes/ArrowTypeConstants.go rename to constants/PrimitiveShape.go index da365e4..01acf18 100644 --- a/attributes/ArrowTypeConstants.go +++ b/constants/PrimitiveShape.go @@ -1,4 +1,4 @@ -package attributes +package constants // PrimitiveShape edge arrow types type PrimitiveShape string diff --git a/attributes/SplinesConstants.go b/constants/Splines.go similarity index 97% rename from attributes/SplinesConstants.go rename to constants/Splines.go index 0861323..9048cd1 100644 --- a/attributes/SplinesConstants.go +++ b/constants/Splines.go @@ -1,4 +1,4 @@ -package attributes +package constants // Splines controls how, and if, edges are represented type Splines string diff --git a/edgeData.go b/edgeData.go index c2da740..77d5619 100644 --- a/edgeData.go +++ b/edgeData.go @@ -6,6 +6,7 @@ import ( "io" "github.com/wwmoraes/dot/attributes" + "github.com/wwmoraes/dot/constants" ) type edgeData struct { @@ -34,25 +35,25 @@ func (thisEdge *edgeData) To() Node { // Solid sets the edge attribute "style" to "solid" // Default style func (thisEdge *edgeData) Solid() Edge { - thisEdge.SetAttribute(attributes.KeyStyle, attributes.NewString("solid")) + thisEdge.SetAttribute(constants.KeyStyle, attributes.NewString("solid")) return thisEdge } // Bold sets the edge attribute "style" to "bold" func (thisEdge *edgeData) Bold() Edge { - thisEdge.SetAttribute(attributes.KeyStyle, attributes.NewString("bold")) + thisEdge.SetAttribute(constants.KeyStyle, attributes.NewString("bold")) return thisEdge } // Dashed sets the edge attribute "style" to "dashed" func (thisEdge *edgeData) Dashed() Edge { - thisEdge.SetAttribute(attributes.KeyStyle, attributes.NewString("dashed")) + thisEdge.SetAttribute(constants.KeyStyle, attributes.NewString("dashed")) return thisEdge } // Dotted sets the edge attribute "style" to "dotted" func (thisEdge *edgeData) Dotted() Edge { - thisEdge.SetAttribute(attributes.KeyStyle, attributes.NewString("dotted")) + thisEdge.SetAttribute(constants.KeyStyle, attributes.NewString("dotted")) return thisEdge } @@ -72,10 +73,10 @@ func (thisEdge *edgeData) EdgesTo(to Node) []Edge { } func (thisEdge *edgeData) WriteTo(device io.Writer) (n int64, err error) { - denoteEdge := attributes.EdgeTypeUndirected + denoteEdge := constants.EdgeTypeUndirected if thisEdge.graph.Root().Type() == GraphTypeDirected { - denoteEdge = attributes.EdgeTypeDirected + denoteEdge = constants.EdgeTypeDirected } written32, err := fmt.Fprintf(device, `"%s"%s"%s"`, thisEdge.From().ID(), denoteEdge, thisEdge.To().ID()) diff --git a/sample/sample.go b/sample/sample.go index decb24a..4aab5ce 100644 --- a/sample/sample.go +++ b/sample/sample.go @@ -6,7 +6,7 @@ import ( "os" "github.com/wwmoraes/dot" - "github.com/wwmoraes/dot/attributes" + "github.com/wwmoraes/dot/constants" "github.com/wwmoraes/dot/formatters" ) @@ -43,7 +43,7 @@ func main() { dot.WithCluster(), ) - clusterA.SetAttributeString(attributes.KeyLabel, "Cluster A") + clusterA.SetAttributeString(constants.KeyLabel, "Cluster A") log.Println("creating node one...") insideOne := clusterA.Node("one") @@ -57,7 +57,7 @@ func main() { dot.WithCluster(), ) - clusterB.SetAttributeString(attributes.KeyLabel, "Cluster B") + clusterB.SetAttributeString(constants.KeyLabel, "Cluster B") log.Println("creating node three...") insideThree := clusterB.Node("three") diff --git a/sonar-project.properties b/sonar-project.properties index 7ea6861..05e5ac0 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,7 +5,7 @@ sonar.projectKey=wwmoraes_dot sonar.sourceEncoding=UTF-8 sonar.sources=. -sonar.exclusions=GraphTypes.go,**/*_test.go,**/*Constants.go,dottest/*.go +sonar.exclusions=GraphTypes.go,**/*_test.go,constants/*.go,dottest/*.go sonar.tests=. sonar.language=go