File tree Expand file tree Collapse file tree 4 files changed +49
-1
lines changed Expand file tree Collapse file tree 4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change
1
+ module oop
2
+
3
+ go 1.16
4
+
5
+ require github.com/stretchr/testify v1.7.0
Original file line number Diff line number Diff line change
1
+ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 =
2
+ github.com/davecgh/go-spew v1.1.0 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
3
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
4
+ github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
5
+ github.com/stretchr/objx v0.1.0 /go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME =
6
+ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY =
7
+ github.com/stretchr/testify v1.7.0 /go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg =
8
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM =
9
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
10
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo =
11
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ https://code.tutsplus.com/tutorials/lets-go-object-oriented-programming-in-golan
13
13
import "fmt"
14
14
15
15
type Animal struct {
16
+ Name string `json:"name"`
16
17
lives int
17
18
}
18
19
@@ -69,7 +70,7 @@ func (*Cat) Meow() string {
69
70
return "meow"
70
71
}
71
72
72
- // overriding:
73
+ // Die overriding:
73
74
func (c * Cat ) Die () string {
74
75
c .lives --
75
76
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "testing"
6
+
7
+ "github.com/stretchr/testify/assert"
8
+ "github.com/stretchr/testify/require"
9
+ )
10
+
11
+ func TestCatJSON (t * testing.T ) {
12
+ tests := []struct {
13
+ name string
14
+ b []byte
15
+ want Cat
16
+ }{
17
+ {
18
+ b : []byte (`{"name":"Cheshire"}` ),
19
+ want : Cat {Animal : & Animal {Name : "Cheshire" }},
20
+ },
21
+ }
22
+
23
+ for _ , tt := range tests {
24
+ t .Run (tt .name , func (t * testing.T ) {
25
+ var got Cat
26
+ err := json .Unmarshal (tt .b , & got )
27
+ require .NoError (t , err )
28
+ assert .Equal (t , tt .want , got )
29
+ })
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments