-
Notifications
You must be signed in to change notification settings - Fork 4
/
examples_test.go
115 lines (112 loc) · 3.33 KB
/
examples_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
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
package set_test
// import (
// "fmt"
// "github.com/nofeaturesonlybugs/set"
// )
// func ExampleValue_To_addressability() {
// fmt.Println("When using Value.To the target Value must be addressable.")
// //
// {
// var value bool
// if err := set.V(value).To(true); err != nil {
// // Expected
// fmt.Println("1. Error because address-of value was not passed.")
// } else {
// fmt.Printf("1. Value is %v\n", value)
// }
// }
// {
// var value bool
// if err := set.V(&value).To(true); err != nil {
// fmt.Println("2. Error because address-of value was not passed.")
// } else {
// // Expected
// fmt.Printf("2. Value is %v\n", value)
// }
// }
// {
// var value *int
// if err := set.V(value).To(42); err != nil {
// // Expected
// fmt.Println("3. Even though value is a pointer itself its address still needs to be passed.")
// if value == nil {
// // Expected
// fmt.Println("3. Also worth noting the pointer remains nil.")
// }
// } else {
// fmt.Printf("3. Value is %v\n", value)
// }
// }
// {
// var value *int
// if err := set.V(&value).To(42); err != nil {
// fmt.Println("4. Even though value is a pointer itself its address still needs to be passed.")
// if value == nil {
// fmt.Println("4. Also worth noting the pointer remains nil.")
// }
// } else {
// // Expected
// fmt.Printf("4. Value is %v\n", *value)
// if value != nil {
// // Expected
// fmt.Println("4. A pointer-to-int was created!")
// }
// }
// }
// {
// var value ***int
// if err := set.V(&value).To(42); err != nil {
// fmt.Println("5. Even though value is a pointer itself its address still needs to be passed.")
// if value == nil {
// fmt.Println("5. Also worth noting the pointer remains nil.")
// }
// } else {
// // Expected
// fmt.Printf("5. Value is %v\n", ***value)
// fmt.Println("5. Multiple pointers had to be created for this to work!")
// }
// }
// {
// value := new(int)
// if err := set.V(value).To(42); err != nil {
// fmt.Println("6. Even though value is a pointer itself its address still needs to be passed.")
// } else {
// // Expected
// fmt.Printf("6. Value is %v\n", *value)
// }
// }
// {
// value := new(**int)
// if err := set.V(value).To(42); err != nil {
// fmt.Println("7. Even though value is a pointer itself its address still needs to be passed.")
// } else {
// // Expected
// fmt.Printf("7. Value is %v\n", ***value)
// }
// }
// {
// var value string
// if err := set.V(&value).To("8. It works with strings too."); err == nil {
// fmt.Println(value)
// }
// }
// {
// var value ***string
// if err := set.V(&value).To("9. String pointers are no different."); err == nil {
// fmt.Println(***value)
// }
// }
// // Output: When using Value.To the target Value must be addressable.
// // 1. Error because address-of value was not passed.
// // 2. Value is true
// // 3. Even though value is a pointer itself its address still needs to be passed.
// // 3. Also worth noting the pointer remains nil.
// // 4. Value is 42
// // 4. A pointer-to-int was created!
// // 5. Value is 42
// // 5. Multiple pointers had to be created for this to work!
// // 6. Value is 42
// // 7. Value is 42
// // 8. It works with strings too.
// // 9. String pointers are no different.
// }