-
Notifications
You must be signed in to change notification settings - Fork 2
/
options_test.go
145 lines (137 loc) · 5.03 KB
/
options_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
// Copyright (c) 2023 0x6flab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0
package namegenerator_test
import (
"testing"
"github.com/0x6flab/namegenerator"
)
func TestOptions(t *testing.T) {
testcase := []struct {
description string
options []namegenerator.Options
prefix string
suffix string
expectedFirstNames []string
expectedSecondNames []string
separator string
}{
{
description: "without gender option",
options: []namegenerator.Options{},
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "with male gender option",
options: []namegenerator.Options{namegenerator.WithGender(namegenerator.Male)},
expectedFirstNames: namegenerator.MaleNames,
expectedSecondNames: namegenerator.FamilyNames,
separator: "-",
},
{
description: "with female gender option",
options: []namegenerator.Options{namegenerator.WithGender(namegenerator.Female)},
expectedFirstNames: namegenerator.FemaleNames,
expectedSecondNames: namegenerator.FamilyNames,
separator: "-",
},
{
description: "with non-binary gender option",
options: []namegenerator.Options{namegenerator.WithGender(namegenerator.NonBinary)},
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "without prefix option",
options: []namegenerator.Options{},
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "with prefix option",
options: []namegenerator.Options{namegenerator.WithPrefix("Dr. ")},
prefix: "Dr. ",
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "without suffix option",
options: []namegenerator.Options{},
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "with suffix option",
options: []namegenerator.Options{namegenerator.WithSuffix(" Jr.")},
suffix: " Jr.",
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "with prefix and suffix option",
options: []namegenerator.Options{namegenerator.WithPrefix("Dr. "), namegenerator.WithSuffix(" Jr.")},
prefix: "Dr. ",
suffix: " Jr.",
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "with female gender and prefix and suffix option",
options: []namegenerator.Options{namegenerator.WithGender(namegenerator.Female), namegenerator.WithPrefix("Dr. "), namegenerator.WithSuffix(" Jr.")},
prefix: "Dr. ",
suffix: " Jr.",
expectedFirstNames: namegenerator.FemaleNames,
expectedSecondNames: namegenerator.FamilyNames,
separator: "-",
},
{
description: "with random string option",
options: []namegenerator.Options{namegenerator.WithRandomString(5)},
suffix: "",
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "with default separator",
options: []namegenerator.Options{namegenerator.WithSeparator("-")},
suffix: "",
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "-",
},
{
description: "with different separator",
options: []namegenerator.Options{namegenerator.WithSeparator("*")},
suffix: "",
expectedFirstNames: namegenerator.GeneralNames,
expectedSecondNames: namegenerator.GeneralNames,
separator: "*",
},
}
for _, tc := range testcase {
t.Run(tc.description, func(t *testing.T) {
nameGenerator := namegenerator.NewGenerator()
name := nameGenerator.Generate(tc.options...)
test(t, name, tc.prefix, tc.suffix, tc.separator, tc.expectedFirstNames, tc.expectedSecondNames)
names := nameGenerator.GenerateMultiple(5, tc.options...)
if len(names) != 5 {
t.Errorf("Expected 5 names, got %d", len(names))
}
for _, name := range names {
test(t, name, tc.prefix, tc.suffix, tc.separator, tc.expectedFirstNames, tc.expectedSecondNames)
}
})
}
}