-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmutagenesis.go
More file actions
118 lines (112 loc) · 2.24 KB
/
mutagenesis.go
File metadata and controls
118 lines (112 loc) · 2.24 KB
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
package figtree
import (
"flag"
"time"
)
func (m Mutagenesis) Kind() string {
switch m {
case tString:
return "string|*string"
case tBool:
return "bool|*bool"
case tInt:
return "int|*int"
case tInt64:
return "int64|*int64"
case tFloat64:
return "float64|*float64"
case tDuration, tUnitDuration:
return "time.Duration|*time.Duration"
case tList:
return "ListFlag|*ListFlag|[]string|*[]string"
case tMap:
return "MapFlag|*MapFlag|map[string]string|*map[string]string"
default:
return string(m)
}
}
// MutagenesisOfFig returns the Mutagensis of the name
func (tree *figTree) MutagenesisOfFig(name string) Mutagenesis {
tree.mu.RLock()
defer tree.mu.RUnlock()
name = tree.resolveName(name)
fruit, ok := tree.figs[name]
if !ok {
return ""
}
return fruit.Mutagenesis
}
func MutagenesisOf(what interface{}) Mutagenesis {
switch x := what.(type) {
case Value:
return x.Mutagensis
case flag.Value:
fv, e := toFloat64(x.String())
if e == nil {
return MutagenesisOf(fv)
}
i64v, e := toInt64(x.String())
if e == nil {
return MutagenesisOf(i64v)
}
iv, e := toInt(x.String())
if e == nil {
return MutagenesisOf(iv)
}
bv, e := toBool(x.String())
if e == nil {
return MutagenesisOf(bv)
}
sv, e := toStringSlice(x.String())
if e == nil {
return MutagenesisOf(sv)
}
mv, e := toStringMap(x.String())
if e == nil {
return MutagenesisOf(mv)
}
return ""
case int:
return tInt
case *int:
return tInt
case *int64:
return tInt64
case int64:
return tInt64
case string:
return tString
case *string:
return tString
case bool:
return tBool
case *bool:
return tBool
case *float64:
return tFloat64
case float64:
return tFloat64
case time.Duration:
return tDuration
case *time.Duration:
return tDuration
case []string:
return tList
case *[]string:
return tList
case map[string]string:
return tMap
case *map[string]string:
return tMap
default:
return ""
}
}
// MutagenesisOf accepts anything and allows you to determine the Mutagensis of the type of from what
// Example:
//
// tree.MutagenesisOf("hello") // Returns tString
// tree.MutagenesisOf(42) // Returns tInt
func (tree *figTree) MutagenesisOf(what interface{}) Mutagenesis {
return MutagenesisOf(what)
}