generated from atomicgo/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_test.go
64 lines (51 loc) · 998 Bytes
/
to_test.go
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
package utils_test
import (
"fmt"
"atomicgo.dev/utils"
)
type Person struct {
Name string
Age int
}
func ExampleToJSON() {
person := Person{"John Doe", 42}
json, _ := utils.ToJSON(person)
fmt.Println(json)
// Output:
// {"Name":"John Doe","Age":42}
}
func ExampleToInt() {
fmt.Println(utils.ToInt(1337))
fmt.Println(utils.ToInt(1337.4))
fmt.Println(utils.ToInt(1337.5))
fmt.Println(utils.ToInt(1337.6))
fmt.Println(utils.ToInt("1337"))
fmt.Println(utils.ToInt("1337.4"))
fmt.Println(utils.ToInt("1337.5"))
fmt.Println(utils.ToInt("1337.6"))
// Output:
// 1337
// 1337
// 1338
// 1338
// 1337
// 1337
// 1338
// 1338
}
func ExampleToString() {
person := Person{"John Doe", 42}
fmt.Println(utils.ToString(person))
// Output:
// {John Doe 42}
}
func ExampleToPrettyJSON() {
person := Person{Name: "John Doe", Age: 42}
prettyJSON, _ := utils.ToPrettyJSON(person)
fmt.Println(prettyJSON)
// Output:
// {
// "Name": "John Doe",
// "Age": 42
// }
}