From e080b3a9ce93c3f10b722038f3193397321354e7 Mon Sep 17 00:00:00 2001 From: Chenyu Zhao Date: Sat, 17 Apr 2021 18:48:49 -0600 Subject: [PATCH] Change Card.Marshal* methods to not use pointer receiver --- card.go | 4 ++-- card_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/card.go b/card.go index 8af0d91..f05f2e5 100644 --- a/card.go +++ b/card.go @@ -59,11 +59,11 @@ func NewCards(s string) []Card { return cards } -func (c *Card) MarshalText() ([]byte, error) { +func (c Card) MarshalText() ([]byte, error) { return []byte(c.String()), nil } -func (c *Card) MarshalJSON() ([]byte, error) { +func (c Card) MarshalJSON() ([]byte, error) { return []byte("\"" + c.String() + "\""), nil } diff --git a/card_test.go b/card_test.go index 8fff68f..7ac97fc 100644 --- a/card_test.go +++ b/card_test.go @@ -1,6 +1,7 @@ package cards import ( + "encoding" "encoding/json" "testing" @@ -22,6 +23,15 @@ func TestNewCards(t *testing.T) { assert.Equal(t, []Card{Card(268446761), Card(134224677)}, NewCards("AhKs")) } +func TestMarshalText(t *testing.T) { + var c encoding.TextMarshaler + c = NewCard("Ah") + + b, err := c.MarshalText() + assert.NoError(t, err) + assert.Equal(t, "Ah", string(b)) +} + func TestMarshalJSON(t *testing.T) { cards := []Card{ NewCard("Ah"),