-
Notifications
You must be signed in to change notification settings - Fork 4
/
text_helpers_test.go
178 lines (171 loc) · 3.84 KB
/
text_helpers_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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package genus
import (
"reflect"
"testing"
"github.com/vattle/sqlboiler/bdb"
)
func TestTxtToOne_Uniq(t *testing.T) {
type fields struct {
ForeignKey bdb.ForeignKey
LocalTable struct {
NameGo string
ColumnNameGo string
}
ForeignTable struct {
NameGo string
NamePluralGo string
ColumnNameGo string
ColumnName string
}
Function struct {
Name string
ForeignName string
UsesBytes bool
LocalAssignment string
ForeignAssignment string
}
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{"OK", fields{}, false},
}
for _, tt := range tests {
to := &TxtToOne{
ForeignKey: tt.fields.ForeignKey,
LocalTable: tt.fields.LocalTable,
ForeignTable: tt.fields.ForeignTable,
Function: tt.fields.Function,
}
if err := to.Uniq(); (err != nil) != tt.wantErr {
t.Errorf("%q. TxtToOne.Uniq() error = %v, wantErr %v", tt.name, err, tt.wantErr)
}
}
}
func TestTxtToMany_Uniq(t *testing.T) {
type fields struct {
LocalTable struct {
NameGo string
ColumnNameGo string
}
ForeignTable struct {
NameGo string
NamePluralGo string
NameHumanReadable string
ColumnNameGo string
Slice string
}
Function struct {
Name string
ForeignName string
UsesBytes bool
LocalAssignment string
ForeignAssignment string
}
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{"OK", fields{}, false},
}
for _, tt := range tests {
tm := &TxtToMany{
LocalTable: tt.fields.LocalTable,
ForeignTable: tt.fields.ForeignTable,
Function: tt.fields.Function,
}
if err := tm.Uniq(); (err != nil) != tt.wantErr {
t.Errorf("%q. TxtToMany.Uniq() error = %v, wantErr %v", tt.name, err, tt.wantErr)
}
}
}
func Test_txtsFromToMany(t *testing.T) {
type args struct {
tables []bdb.Table
table bdb.Table
rel bdb.ToManyRelationship
}
tests := []struct {
name string
args args
want TxtToMany
}{
{"OK", args{
[]bdb.Table{},
bdb.Table{
Columns: []bdb.Column{
bdb.Column{
Name: "id",
},
},
},
bdb.ToManyRelationship{Column: "id"},
}, TxtToMany{
LocalTable: struct {
NameGo string
ColumnNameGo string
}{ColumnNameGo: "ID"},
ForeignTable: struct {
NameGo string
NamePluralGo string
NameHumanReadable string
ColumnNameGo string
Slice string
}{Slice: "Slice"},
Function: struct {
Name string
ForeignName string
UsesBytes bool
LocalAssignment string
ForeignAssignment string
}{LocalAssignment: "ID", ForeignName: "X"},
}},
}
for _, tt := range tests {
if got := txtsFromToMany(tt.args.tables, tt.args.table, tt.args.rel); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%q. txtsFromToMany() = %+v, want %+v", tt.name, got, tt.want)
}
}
}
func Test_mkFunctionName(t *testing.T) {
type args struct {
fkeyTableSingular string
foreignTablePluralGo string
fkeyColumn string
toJoinTable bool
}
tests := []struct {
name string
args args
want string
}{
{"OK", args{"user", "Users", "name", false}, "NameUsers"},
}
for _, tt := range tests {
if got := mkFunctionName(tt.args.fkeyTableSingular, tt.args.foreignTablePluralGo, tt.args.fkeyColumn, tt.args.toJoinTable); got != tt.want {
t.Errorf("%q. mkFunctionName() = %v, want %v", tt.name, got, tt.want)
}
}
}
func Test_trimSuffixes(t *testing.T) {
type args struct {
str string
}
tests := []struct {
name string
args args
want string
}{
{"OK", args{"user_id"}, "user"},
{"OK", args{"user"}, "user"},
}
for _, tt := range tests {
if got := trimSuffixes(tt.args.str); got != tt.want {
t.Errorf("%q. trimSuffixes() = %v, want %v", tt.name, got, tt.want)
}
}
}