-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_example_test.go
72 lines (55 loc) · 1.05 KB
/
value_example_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
package truthy_test
import (
"errors"
"fmt"
"time"
"github.com/carlmjohnson/truthy"
)
func ExampleValue() {
var err error
fmt.Println(truthy.Value(err))
err = errors.New("hi")
fmt.Println(truthy.Value(err))
var n int
fmt.Println(truthy.Value(n))
n = 1
fmt.Println(truthy.Value(n))
var p *int
fmt.Println(truthy.Value(p))
p = new(int)
// truthy does not check value underlying pointer!
fmt.Println(truthy.Value(p))
var s string
fmt.Println(truthy.Value(s))
s = " "
fmt.Println(truthy.Value(s))
var b []byte
fmt.Println(truthy.ValueSlice(b))
b = []byte(" ")
fmt.Println(truthy.ValueSlice(b))
m := map[string]string{}
fmt.Println(truthy.ValueMap(m))
m["a"] = "b"
fmt.Println(truthy.ValueMap(m))
var t time.Time
t = t.Local()
// t.IsZero() is still true although t is not the empty value
fmt.Println(truthy.ValueAny(t))
t = t.Add(1 * time.Second)
fmt.Println(truthy.ValueAny(t))
// Output:
// false
// true
// false
// true
// false
// true
// false
// true
// false
// true
// false
// true
// false
// true
}