-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprettyp_test.go
More file actions
128 lines (117 loc) · 3.88 KB
/
prettyp_test.go
File metadata and controls
128 lines (117 loc) · 3.88 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package util
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type SourceLang struct {
En string `json:"en" bson:"en"`
Bn string `json:"bn" bson:"bn"`
}
type UserInfo struct {
Username string `json:"username" bson:"username"`
Email string `json:"email" bson:"email"`
}
func TestPretty(t *testing.T) {
project := struct {
Id int64 `json:"project_id"`
Title string `json:"title"`
Name string `json:"name"`
Budget float64 `json:"budget"`
Active bool `json:"active"`
Tags []string `json:"tags"`
Milestones []int `json:"milestones"`
Metadata map[string]interface{} `json:"metadata"`
NestedStruct struct {
Description string `json:"description"`
Completed bool `json:"completed"`
} `json:"nested_struct"`
}{
Id: 123,
Title: "Test Project",
Name: "Test Name",
Budget: 1000000.50,
Active: true,
Tags: []string{"Go", "JSON", "PrettyPrint"},
Milestones: []int{1, 2, 3, 4},
Metadata: map[string]interface{}{
"created_by": "User123",
"priority": "High",
},
NestedStruct: struct {
Description string `json:"description"`
Completed bool `json:"completed"`
}{
Description: "Nested Struct Description",
Completed: false,
},
}
err := PrettyPrint(project)
assert.NoError(t, err, "PrettyPrint should not return an error")
}
func TestPrettyPrintWithLocation(t *testing.T) {
location := struct {
Id string `bson:"_id,omitempty" json:"id,omitempty"`
Title SourceLang `bson:"title" json:"title"`
Address SourceLang `bson:"address" json:"address"`
Description SourceLang `bson:"description" json:"description"`
MapLink string `bson:"map_link" json:"map_link"`
CreatedAt time.Time `json:"created_at,omitempty" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at,omitempty" bson:"updated_at"`
CreatedBy UserInfo `bson:"created_by" json:"created_by"`
UpdatedBy UserInfo `bson:"updated_by" json:"updated_by"`
}{
Id: "673dcdb47484940c3f9fd08c",
Title: SourceLang{
En: "Uttara, EC",
Bn: "উত্তরা,EC",
},
Address: SourceLang{
En: "8th Floor, Millennium Tower, House 2, Road 7, Sector 3, Uttara",
Bn: "৮ম ফ্লোর, মিলেনিয়াম টাওয়ার, হাউজ ২, রোড ৭, সেক্টর ৩, উত্তরা।",
},
Description: SourceLang{
En: "Uttara Center",
Bn: "উত্তরা কেন্দ্র",
},
MapLink: "https://www.google.com/maps/dir/",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CreatedBy: UserInfo{Username: "creator_user", Email: "creator@example.com"},
UpdatedBy: UserInfo{Username: "updater_user", Email: "updater@example.com"},
}
err := PrettyPrint(location)
assert.NoError(t, err, "PrettyPrint should not return an error")
}
type Owner struct {
Name string `json:"name"`
Email string `json:"email"`
}
func TestPrettyPrintWithCat(t *testing.T) {
cat := struct {
Id string `json:"id"`
Name string `json:"name"`
Breed string `json:"breed"`
Age int `json:"age"`
IsIndoor bool `json:"is_indoor"`
WeightKg float64 `json:"weight_kg"`
FavoriteFoods []string `json:"favorite_foods"`
AdoptedAt time.Time `json:"adopted_at"`
Owner Owner `json:"owner"`
}{
Id: "673dcdb47484940c3f9fd08c",
Name: "Whiskers",
Breed: "British Shorthair",
Age: 3,
IsIndoor: true,
WeightKg: 4.2,
FavoriteFoods: []string{"Tuna", "Salmon", "Chicken"},
AdoptedAt: time.Now(),
Owner: Owner{
Name: "Owner",
Email: "owner@example.com",
},
}
err := PrettyPrint(cat)
assert.NoError(t, err, "PrettyPrint should not return an error")
}