Skip to content

Commit

Permalink
Merge pull request #7 from n-peugnet/omit-empty-for
Browse files Browse the repository at this point in the history
Omit empty for attribute of key element
  • Loading branch information
yaricom authored Dec 13, 2023
2 parents e273fcd + b0b1f5e commit df3a6ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graphml/graphml.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type Key struct {
// The ID of this key element (in form dX, where X denotes the number of occurrences of the key element before the current one)
ID string `xml:"id,attr"`
// The name of element this key is for (graphml|graph|node|edge|hyperedge|port|endpoint|all)
Target KeyForElement `xml:"for,attr"`
Target KeyForElement `xml:"for,attr,omitempty"`
// The name of data-function associated with this key
Name string `xml:"attr.name,attr"`
// The type of input to the data-function associated with this key. (Allowed values: boolean, int, long, float, double, string)
Expand Down
17 changes: 17 additions & 0 deletions graphml/graphml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ func TestGraphML_Encode(t *testing.T) {
assert.Equal(t, resString, outBuf.String())
}

func TestGraphML_Encode_EmptyFor(t *testing.T) {
// build GraphML
gml := NewGraphML("TestGraphML_Encode_EmptyFor")

// register common data-function for all elements
keyForAllName := "keyForAll"
_, err := gml.RegisterKey("", keyForAllName, "", reflect.String, nil)
require.NoError(t, err, "failed to register key")

// encode
outBuf := &bytes.Buffer{}
err = gml.Encode(outBuf, false)

// check results
assert.NotContains(t, outBuf.String(), "for=\"\"", "a key with an empty target should omit the for attribute")
}

func TestGraphML_AddGraph(t *testing.T) {
description := "test graph"
gml := NewGraphML("")
Expand Down

0 comments on commit df3a6ed

Please sign in to comment.