-
Notifications
You must be signed in to change notification settings - Fork 1
/
namer.go
69 lines (56 loc) · 1.88 KB
/
namer.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
package gomocker
import (
"fmt"
"strings"
)
type FuncMockerNamer interface {
MockerName(identifier string) string
ConstructorName(identifier string) string
InvocationName(identifier string) string
ArgumentName(i int, originalArgName string, needPublic bool, isReturnArgument bool) string
}
type InterfaceMockerNamer interface {
MockerName(identifier string) string
MockedName(identifier string) string
ConstructorName(identifier string) string
FunctionAliasName(identifier, functionName string) string
}
type defaultFuncMockerNamer struct{}
func (*defaultFuncMockerNamer) MockerName(typeName string) string {
return makePublic(typeName) + "Mocker"
}
func (*defaultFuncMockerNamer) ConstructorName(typeName string) string {
return "NewMocked" + makePublic(typeName)
}
func (*defaultFuncMockerNamer) InvocationName(typeName string) string {
return makePublic(typeName) + "Invocation"
}
func (*defaultFuncMockerNamer) ArgumentName(i int, name string, needPublic bool, isReturnArgument bool) string {
if name != "" {
if needPublic {
return strings.ToUpper(name[:1]) + name[1:]
}
return name
} else if isReturnArgument {
if needPublic {
return fmt.Sprintf("Out%d", i+1)
}
return fmt.Sprintf("out%d", i+1)
} else if needPublic {
return fmt.Sprintf("Arg%d", i+1)
}
return fmt.Sprintf("arg%d", i+1)
}
type defaultInterfaceMockerNamer struct{}
func (d *defaultInterfaceMockerNamer) MockerName(identifier string) string {
return makePublic(identifier) + "Mocker"
}
func (d *defaultInterfaceMockerNamer) MockedName(identifier string) string {
return "Mocked" + makePublic(identifier)
}
func (d *defaultInterfaceMockerNamer) ConstructorName(identifier string) string {
return "NewMocked" + makePublic(identifier)
}
func (d *defaultInterfaceMockerNamer) FunctionAliasName(identifier, functionName string) string {
return makePublic(identifier) + "_" + makePublic(functionName)
}