forked from huttarichard/refutil
/
unexported.go
60 lines (55 loc) · 1.68 KB
/
unexported.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
package test
// SampleType represent category
// for samples
type SampleType uint
const (
// SampleInt sample int type
SampleInt SampleType = iota
// SampleUint sample uint type
SampleUint
// SampleString sample string type
SampleString
// SampleStringPtr sample string pointer type
SampleStringPtr
// SampleStringNil sample string pointer type which is nil
SampleStringNil
// SampleStringSlice sample string slice type
SampleStringSlice
// SampleChanBool sample booelan chan type
SampleChanBool
// SampleEmptyZeroer sample zeroer struct type which is nil
SampleEmptyZeroer
// SamplePositiveZeroer sample zeroer struct type
SamplePositiveZeroer
// SampleZeroer sample zeroer struct type
SampleZeroer
// SampleStruct sample struct type
SampleStruct
)
var sampleStringValue = "test"
var samples = map[SampleType]interface{}{
SampleInt: sampleInt(1),
SampleUint: sampleUint(1),
SampleString: sampleString(sampleStringValue),
SampleStringNil: sampleStringPtr((*string)(nil)),
SampleStringPtr: sampleStringPtr((*string)(&sampleStringValue)),
SampleStringSlice: sampleStringSlice([]string{sampleStringValue}),
SampleChanBool: sampleChanBool(make(chan bool)),
SampleZeroer: &sampleZeroer{positive: false},
SamplePositiveZeroer: &sampleZeroer{positive: true},
SampleEmptyZeroer: (*sampleZeroer)(nil),
SampleStruct: &sampleStruct{
Test: "test",
test: "test",
interf: "test",
},
}
// Sample return sample interface.
// This is intended for testing unexported types in refutil package
func Sample(t SampleType) interface{} {
m, ok := samples[t]
if !ok {
panic("trying to get unregistered sample")
}
return m
}