forked from zhravan/golearn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_test.go
More file actions
33 lines (26 loc) · 773 Bytes
/
Copy pathjson_test.go
File metadata and controls
33 lines (26 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package json
import "testing"
func TestMarshalPerson(t *testing.T) {
p := Person{Name: "golearn", Email: "golearn@example.com"}
jsonStr, err := MarshalPerson(p)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
expected := `{"name":"golearn","email":"golearn@example.com"}`
if jsonStr != expected {
t.Errorf("Expected %s, got %s", expected, jsonStr)
}
}
func TestUnmarshalPerson(t *testing.T) {
jsonStr := `{"name":"golearn","email":"golearn@example.com"}`
p, err := UnmarshalPerson(jsonStr)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if p.Name != "golearn" {
t.Errorf("Expected name 'golearn', got %s", p.Name)
}
if p.Email != "golearn@example.com" {
t.Errorf("Expected email 'golearn@example.com', got %s", p.Email)
}
}