forked from charithe/durationcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.go
133 lines (81 loc) · 2.89 KB
/
a.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package a
import (
"b"
"time"
)
const (
timeout = 10 * time.Second
foo = 10
)
type myStruct struct {
fieldA int
fieldB time.Duration
fieldC *int
}
func validCases() {
y := 10
ms := myStruct{fieldA: 10, fieldB: 10 * time.Second, fieldC: func(v int) *int { return &v }(10)}
intArr := []int{1}
_ = time.Second * 30
_ = time.Duration(10) * time.Second
_ = time.Second * time.Duration(10)
_ = time.Duration(10+20*5) * time.Second
_ = time.Second * time.Duration(10+20*5)
_ = time.Duration((foo + 20)) * time.Second
_ = time.Second * time.Duration((foo + 20))
_ = 2 * 24 * time.Hour
_ = time.Hour * 2 * 24
_ = -1 * time.Hour
_ = time.Hour * -1
_ = time.Duration(y) * time.Second
_ = time.Second * time.Duration(y)
_ = time.Duration(someDurationMillis()) * time.Millisecond
_ = time.Millisecond * time.Duration(someDurationMillis())
_ = time.Duration(*somePointerDurationMillis()) * time.Millisecond
_ = time.Millisecond * time.Duration(*somePointerDurationMillis())
_ = timeout / time.Millisecond
_ = foo * time.Second
_ = time.Second * foo
_ = time.Duration(ms.fieldA) * time.Second
_ = time.Second * time.Duration(ms.fieldA)
_ = time.Duration(*ms.fieldC) * time.Second
_ = time.Second * time.Duration(*ms.fieldC)
_ = b.SomeInt * time.Second
_ = time.Second * b.SomeInt
_ = time.Duration(intArr[0]) * time.Second
}
func invalidCases() {
x := 30 * time.Second
ms := myStruct{fieldA: 10, fieldB: 10 * time.Second}
tdArr := []time.Duration{1}
_ = x * time.Second // want `Multiplication of durations`
_ = time.Second * x // want `Multiplication of durations`
_ = timeout * time.Millisecond // want `Multiplication of durations`
_ = someDuration() * time.Second // want `Multiplication of durations`
_ = time.Millisecond * someDuration() // want `Multiplication of durations`
_ = *somePointerDuration() * time.Second // want `Multiplication of durations`
_ = time.Millisecond * *somePointerDuration() // want `Multiplication of durations`
_ = (30 * time.Second) * time.Millisecond // want `Multiplication of durations`
_ = time.Millisecond * (30 * time.Second) // want `Multiplication of durations`
_ = time.Millisecond * time.Second * 1 // want `Multiplication of durations`
_ = 1 * time.Second * (time.Second) // want `Multiplication of durations`
_ = ms.fieldB * time.Second // want `Multiplication of durations`
_ = time.Second * ms.fieldB // want `Multiplication of durations`
_ = b.SomeDuration * time.Second // want `Multiplication of durations`
_ = time.Second * b.SomeDuration // want `Multiplication of durations`
_ = time.Duration(tdArr[0]) * time.Second // want `Multiplication of durations`
}
func someDuration() time.Duration {
return 10 * time.Second
}
func someDurationMillis() int {
return 10
}
func somePointerDuration() *time.Duration {
v := 10 * time.Second
return &v
}
func somePointerDurationMillis() *int {
v := 10
return &v
}