From d551e9198534908d482086c4f43920c8d0987870 Mon Sep 17 00:00:00 2001 From: Yura Date: Fri, 5 Mar 2021 14:49:13 +0300 Subject: [PATCH] Serializating the Tag structure (#47) closes #46 --- v5/marshaling.go | 7 +++++++ v5/marshaling_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 v5/marshaling.go create mode 100644 v5/marshaling_test.go diff --git a/v5/marshaling.go b/v5/marshaling.go new file mode 100644 index 0000000..6cc65cf --- /dev/null +++ b/v5/marshaling.go @@ -0,0 +1,7 @@ +package v5 + +import "encoding/json" + +func (t Tag) MarshalJSON() ([]byte, error) { + return json.Marshal(t.Name) +} diff --git a/v5/marshaling_test.go b/v5/marshaling_test.go new file mode 100644 index 0000000..199b22a --- /dev/null +++ b/v5/marshaling_test.go @@ -0,0 +1,24 @@ +package v5 + +import ( + "encoding/json" + "reflect" + "testing" +) + +func TestTag_MarshalJSON(t *testing.T) { + tags := []Tag{ + {"first", "#3e89b6", false}, + {"second", "#ffa654", false}, + } + names := []byte(`["first","second"]`) + str, err := json.Marshal(tags) + + if err != nil { + t.Errorf("%v", err.Error()) + } + + if !reflect.DeepEqual(str, names) { + t.Errorf("Marshaled: %#v\nExpected: %#v\n", str, names) + } +}