File tree Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -71,3 +71,8 @@ func (e Edge) From() Node {
71
71
func (e Edge ) To () Node {
72
72
return e .to
73
73
}
74
+
75
+ // Returns attributes for this edge
76
+ func (e Edge ) GetAttributes () map [string ]interface {} {
77
+ return e .AttributesMap .GetAttributes ()
78
+ }
Original file line number Diff line number Diff line change @@ -119,3 +119,17 @@ func TestNonStringAttribute(t *testing.T) {
119
119
t .Errorf ("got [%v] want [%v]" , got , want )
120
120
}
121
121
}
122
+
123
+ func TestEdgeGetAttributes (t * testing.T ) {
124
+ di := NewGraph (Directed )
125
+ n1 := di .Node ("A" )
126
+ n2 := di .Node ("B" )
127
+ e := di .Edge (n1 , n2 ).Label ("edge-label" ).Attr ("foo" , "bar" )
128
+ attrs := e .GetAttributes ()
129
+ if v , ok := attrs ["label" ]; ! ok || v != "edge-label" {
130
+ t .Errorf ("expected label=edge-label, got %v" , attrs )
131
+ }
132
+ if v , ok := attrs ["foo" ]; ! ok || v != "bar" {
133
+ t .Errorf ("expected foo=bar, got %v" , attrs )
134
+ }
135
+ }
Original file line number Diff line number Diff line change @@ -418,3 +418,12 @@ func (g *Graph) EdgesMap() map[string][]Edge {
418
418
func (g * Graph ) HasNode (n Node ) bool {
419
419
return g == n .graph
420
420
}
421
+
422
+ // GetAttributes returns a copy of the attributes
423
+ func (am * AttributesMap ) GetAttributes () map [string ]interface {} {
424
+ copyMap := make (map [string ]interface {}, len (am .attributes ))
425
+ for k , v := range am .attributes {
426
+ copyMap [k ] = v
427
+ }
428
+ return copyMap
429
+ }
Original file line number Diff line number Diff line change @@ -414,3 +414,15 @@ func TestFindNodeWithLabel(t *testing.T) {
414
414
t .Fail ()
415
415
}
416
416
}
417
+
418
+ func TestNodeGetAttributesCopy (t * testing.T ) {
419
+ di := NewGraph (Directed )
420
+ n := di .Node ("A" )
421
+ n .Attr ("foo" , "bar" )
422
+ attrs := n .GetAttributes ()
423
+ attrs ["foo" ] = "bar"
424
+ attrs2 := n .GetAttributes ()
425
+ if v , ok := attrs2 ["foo" ]; ! ok || v != "bar" {
426
+ t .Errorf ("expected foo=bar, got %v" , attrs2 )
427
+ }
428
+ }
You can’t perform that action at this time.
0 commit comments