Skip to content

Commit

Permalink
Change Card.Marshal* methods to not use pointer receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
zchenyu committed Apr 18, 2021
1 parent a9cd225 commit e080b3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions card_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cards

import (
"encoding"
"encoding/json"
"testing"

Expand All @@ -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"),
Expand Down

0 comments on commit e080b3a

Please sign in to comment.