Serializating the Tag structure (#47)

closes #46
This commit is contained in:
Yura 2021-03-05 14:49:13 +03:00 committed by GitHub
parent e68199efb3
commit d551e91985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

7
v5/marshaling.go Normal file
View File

@ -0,0 +1,7 @@
package v5
import "encoding/json"
func (t Tag) MarshalJSON() ([]byte, error) {
return json.Marshal(t.Name)
}

24
v5/marshaling_test.go Normal file
View File

@ -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)
}
}