forked from manveru/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faker_test.go
502 lines (478 loc) · 14.7 KB
/
faker_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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
package faker
import (
"fmt"
"math/rand"
"testing"
. "github.com/manveru/gobdd"
)
var (
f, err = New("en")
)
func ExampleFaker_Name() {
fake, _ := New("en")
fake.Rand = rand.New(rand.NewSource(42))
fmt.Println(fake.Name())
// Output: Adriana Crona
}
func TestEverything(*testing.T) {}
func init() {
defer PrintSpecReport()
Describe("english faker", func() {
fake, _ := New("en")
fake.Rand = rand.New(rand.NewSource(42))
BeforeEach(func() {
fake.Rand = rand.New(rand.NewSource(42))
})
It("makes fake city names", func() {
Expect(func() string { return fake.City() },
Returns, "West Kim", "Jackyland", "New Nathen")
})
It("makes fake street names", func() {
Expect(func() string { return fake.StreetName() },
Returns, "Willms Grove", "Jacky Harbor", "Lesch Parkway")
})
It("makes fake street addresses", func() {
Expect(func() string { return fake.StreetAddress() }, Returns,
"562 Dustin Prairie", "24678 Nathen Extension", "465 Altenwerth Hollow")
})
It("makes fake post codes", func() {
Expect(func() string { return fake.PostCode() },
Returns, "73248-0225", "20510-7716", "34655")
})
It("makes fake street suffixes", func() {
Expect(func() string { return fake.StreetSuffix() },
Returns, "Island", "Gardens", "Grove")
})
It("makes fake city suffixes", func() {
Expect(func() string { return fake.CitySuffix() },
Returns, "burgh", "ville", "mouth")
})
It("makes fake city prefixes", func() {
Expect(func() string { return fake.CityPrefix() },
Returns, "Lake", "West", "New")
})
It("makes random US state abbreviations", func() {
Expect(func() string { return fake.StateAbbr() },
Returns, "AZ", "FL", "VA")
})
It("makes random US state names", func() {
Expect(func() string { return fake.State() },
Returns, "Colorado", "Pennsylvania", "Maine")
})
It("makes random country names", func() {
Expect(func() string { return fake.Country() },
Returns, "Tajikistan", "Cameroon", "Cote d'Ivoire")
})
It("makes random latitude", func() {
Expect(fake.Latitude(), ToEqual, -22.85489501160613)
Expect(fake.Latitude(), ToEqual, -78.11991057716678)
Expect(fake.Latitude(), ToEqual, 18.736893280555567)
})
It("makes random longitude", func() {
Expect(fake.Longitude(), ToEqual, -45.70979002321226)
Expect(fake.Longitude(), ToEqual, -156.23982115433355)
Expect(fake.Longitude(), ToEqual, 37.47378656111113)
})
It("makes fake company names", func() {
Expect(func() string { return fake.CompanyName() }, Returns,
"Willms, Crona and Swift",
"Schaefer-Maggio",
"Hartmann, Huels and Wolff")
})
It("makes fake company suffixes", func() {
Expect(func() string { return fake.CompanySuffix() },
Returns, "and Sons", "Group", "Inc")
})
It("makes company catch phrases", func() {
Expect(func() string { return fake.CompanyCatchPhrase() }, Returns,
"Balanced next generation circuit",
"Object-based high-level task-force",
"Organized actuating intranet")
})
It("makes company bs", func() {
Expect(func() string { return fake.CompanyBs() }, Returns,
"deliver dynamic e-markets",
"iterate impactful e-services",
"utilize robust eyeballs")
})
It("makes names", func() {
Expect(func() string { return fake.Name() }, Returns,
"Adriana Crona", "Miss Stuart Maggio", "Nathen Huels")
})
It("makes first names", func() {
Expect(func() string { return fake.FirstName() },
Returns, "Jeromy", "Adriana", "Kim")
})
It("makes last names", func() {
Expect(func() string { return fake.LastName() }, Returns,
"Willms", "Willms", "Crona")
})
It("makes name prefixes", func() {
Expect(func() string { return fake.NamePrefix() }, Returns,
"Mr.", "Ms.", "Miss")
})
It("makes name suffixes", func() {
Expect(func() string { return fake.NameSuffix() }, Returns,
"Jr.", "PhD", "Sr.")
})
It("makes job titles", func() {
Expect(func() string { return fake.JobTitle() }, Returns,
"Human Factors Planner",
"Legacy Mobility Representative",
"Senior Accounts Architect")
})
It("makes ", func() {
Expect(func() string { return fake.Email() }, Returns,
})
It("makes ", func() {
Expect(func() string { return fake.FreeEmail() }, Returns,
})
It("makes ", func() {
Expect(func() string { return fake.SafeEmail() }, Returns,
})
It("makes ", func() {
Expect(func() string { return fake.IPv4Address().String() },
Returns, "249.195.38.38", "45.21.213.246", "82.77.201.235")
})
It("makes ", func() {
Expect(func() string { return fake.IPv6Address().String() }, Returns,
"2001:cafe:64b1:b44b:f284:923e:d7df:7a61",
"2001:cafe:5ba5:8588:9b70:75d3:19f9:826f",
"2001:cafe:9ee7:badc:4f8c:8f6d:ce04:cf79")
})
It("makes ", func() {
Expect(func() string { return fake.URL() }, Returns,
"http://willms.biz/keely.hartmann",
"http://lueilwitzboehm.net/marilou.rodriguez",
"http://jerde.name/abdul.jaskolski")
})
It("makes random words", func() {
Expect(fake.Words(0, false), ToDeepEqual, []string{})
Expect(fake.Words(1, false), ToDeepEqual, []string{"at"})
Expect(fake.Words(2, false), ToDeepEqual, []string{"illum", "ut"})
Expect(fake.Words(3, false), ToDeepEqual, []string{"est", "sit", "soluta"})
Expect(fake.Words(0, true), ToDeepEqual, []string{})
Expect(fake.Words(1, true), ToDeepEqual, []string{"stabilis"})
Expect(fake.Words(2, true), ToDeepEqual, []string{"sunt", "theologus"})
Expect(fake.Words(3, true), ToDeepEqual, []string{"facere", "super", "adipiscor"})
})
It("makes random characters", func() {
Expect(fake.Characters(0), ToEqual, "")
Expect(fake.Characters(50), ToEqual, "v7ottxf08ku5u1e8barnpqxfqhposxhm1ur5wc7jqy6ccjw8bx")
for n := 0; n < 100; n++ {
Expect(len(fake.Characters(n)), ToEqual, n)
}
})
It("makes random sentences", func() {
Expect(fake.Sentence(0, false), ToEqual, "Illum ut est sit soluta.")
Expect(fake.Sentence(15, false), ToEqual, "Numquam nobis sunt quaerat ea dolores facere deleniti culpa numquam ut distinctio maxime consequatur est qui corporis sunt.")
Expect(fake.Sentence(0, true), ToEqual, "Agnosco odit voluptas sumo ipsa.")
Expect(fake.Sentence(15, true), ToEqual, "Tempus solutio umbra hic vulnero baiulus colo blanditiis circumvenio nostrum eius fugit cogo centum fuga.")
})
It("makes random paragraphs", func() {
Expect(fake.Paragraph(0, false), ToEqual, "")
Expect(fake.Paragraph(2, false), ToEqual, "Illum ut est sit soluta nulla numquam nobis. Quaerat ea dolores facere.")
Expect(fake.Paragraph(4, false), ToEqual, "Culpa numquam ut distinctio maxime. Est qui corporis sunt officia odit et. Odit molestias voluptas porro. Magnam ipsa corporis.")
Expect(fake.Paragraph(0, true), ToEqual, "")
Expect(fake.Paragraph(2, true), ToEqual, "Non averto quisquam corpus. Baiulus colo blanditiis.")
Expect(fake.Paragraph(4, true), ToEqual, "Tersus qui suscipit tenus et quod. Comprehendo coepi terminatio claudeo suscipio. Voluptas bis voluptatibus voluptatibus sol. Terebro arto autem canonicus stabilis defungo adnuo at.")
})
It("makes random US phone numbers", func() {
Expect(func() string { return fake.PhoneNumber() }, Returns,
"(386)730-7410", "107.113.0706", "478-375-8633 x188")
})
})
Describe("german faker", func() {
fake, _ := New("de")
fake.Rand = rand.New(rand.NewSource(42))
BeforeEach(func() {
fake.Rand = rand.New(rand.NewSource(42))
})
It("makes fake city names", func() {
Expect(func() string { return fake.City() },
Returns, "West Collien", "Neostadt", "Neu Markus")
})
It("makes fake street names", func() {
Expect(func() string { return fake.StreetName() },
Returns, "Fichtestr.", "Eichenkamp", "Heinrich-Böll-Str.")
})
It("makes fake street addresses", func() {
Expect(func() string { return fake.StreetAddress() }, Returns,
"Eichenkamp 85a", "Große Kirchstr. 21c", "Händelstr. 0856")
})
It("makes fake post codes", func() {
Expect(func() string { return fake.PostCode() },
Returns, "01478", "60712", "72581")
})
It("makes fake city suffixes", func() {
Expect(func() string { return fake.CitySuffix() },
Returns, "stadt", "land", "scheid")
})
It("makes fake city prefixes", func() {
Expect(func() string { return fake.CityPrefix() },
Returns, "Alt", "West", "Neu")
})
It("makes random German state abbreviations", func() {
Expect(func() string { return fake.StateAbbr() },
Returns, "BE", "SH", "HB")
})
It("makes random country names", func() {
Expect(func() string { return fake.Country() },
Returns, "Turks- und Caicosinseln", "Turks- und Caicosinseln", "Guinea")
})
It("makes random latitude", func() {
Expect(fake.Latitude(), ToEqual, -22.85489501160613)
Expect(fake.Latitude(), ToEqual, -78.11991057716678)
Expect(fake.Latitude(), ToEqual, 18.736893280555567)
})
It("makes random longitude", func() {
Expect(fake.Longitude(), ToEqual, -45.70979002321226)
Expect(fake.Longitude(), ToEqual, -156.23982115433355)
Expect(fake.Longitude(), ToEqual, 37.47378656111113)
})
It("makes fake company names", func() {
Expect(func() string { return fake.CompanyName() }, Returns,
"Lang, Schindzielorz und Bühler",
"Döring-Spank",
"Eberhard, Wimmer und Thust")
})
It("makes fake company suffixes", func() {
Expect(func() string { return fake.CompanySuffix() },
Returns, "Gruppe", "Gruppe", "Gruppe")
})
It("makes first names", func() {
Expect(func() string { return fake.FirstName() },
Returns, "Dorian", "Leroy", "Collien")
})
It("makes last names", func() {
Expect(func() string { return fake.LastName() }, Returns,
"Urbansky", "Lang", "Schindzielorz")
})
It("makes name prefixes", func() {
Expect(func() string { return fake.NamePrefix() }, Returns,
"Fr.", "Prof. Dr.", "Hr.")
})
It("makes name suffixes", func() {
Expect(func() string { return fake.NameSuffix() }, Returns,
"von der", "von der", "von der")
})
It("makes all kinds of email addresses", func() {
Expect(func() string { return fake.Email() }, Returns,
})
It("makes free email addresses", func() {
Expect(func() string { return fake.FreeEmail() }, Returns,
})
It("makes safe email addreses", func() {
Expect(func() string { return fake.SafeEmail() }, Returns,
})
It("makes ", func() {
Expect(func() string { return fake.IPv4Address().String() },
Returns, "249.195.38.38", "45.21.213.246", "82.77.201.235")
})
It("makes ", func() {
Expect(func() string { return fake.IPv6Address().String() }, Returns,
"2001:cafe:64b1:b44b:f284:923e:d7df:7a61",
"2001:cafe:5ba5:8588:9b70:75d3:19f9:826f",
"2001:cafe:9ee7:badc:4f8c:8f6d:ce04:cf79")
})
It("makes ", func() {
Expect(func() string { return fake.URL() }, Returns,
"http://lang.de/sandy.eberhard",
"http://kastenlewke.org/josua.rossberg",
"http://ruckdeschel.com/kaan.herweg")
})
It("makes random characters", func() {
Expect(fake.Characters(0), ToEqual, "")
Expect(fake.Characters(50), ToEqual, "v7ottxf08ku5u1e8barnpqxfqhposxhm1ur5wc7jqy6ccjw8bx")
for n := 0; n < 100; n++ {
Expect(len(fake.Characters(n)), ToEqual, n)
}
})
It("makes random German phone numbers", func() {
Expect(func() string { return fake.PhoneNumber() }, Returns,
"(02461) 0430723", "+49-4385-21431614", "(0804) 543021034")
})
})
}
func Returns(fun func() string, expected ...string) (string, bool) {
for _, s := range expected {
value := fun()
if value != s {
return fmt.Sprintf("\texpected: %#v\n\t to be: %#v\n", s, value), false
}
}
return "", true
}
func BenchmarkCellPhone(b *testing.B) {
for i := 0; i < b.N; i++ {
f.CellPhoneNumber()
}
}
func BenchmarkCity(b *testing.B) {
for i := 0; i < b.N; i++ {
f.City()
}
}
func BenchmarkCityPrefix(b *testing.B) {
for i := 0; i < b.N; i++ {
f.CityPrefix()
}
}
func BenchmarkCitySuffix(b *testing.B) {
for i := 0; i < b.N; i++ {
f.CitySuffix()
}
}
func BenchmarkCmapnyBS(b *testing.B) {
for i := 0; i < b.N; i++ {
f.CompanyBs()
}
}
func BenchmarkCompagnyCatchPhrase(b *testing.B) {
for i := 0; i < b.N; i++ {
f.CompanyCatchPhrase()
}
}
func BenchmarkCompagnyName(b *testing.B) {
for i := 0; i < b.N; i++ {
f.CompanyName()
}
}
func BenchmarkCompagnySuffix(b *testing.B) {
for i := 0; i < b.N; i++ {
f.CompanySuffix()
}
}
func BenchmarkCountry(b *testing.B) {
for i := 0; i < b.N; i++ {
f.Country()
}
}
func BenchmarkDomainName(b *testing.B) {
for i := 0; i < b.N; i++ {
f.DomainName()
}
}
func BenchmarkDomainSuffix(b *testing.B) {
for i := 0; i < b.N; i++ {
f.DomainSuffix()
}
}
func BenchmarkDomainWord(b *testing.B) {
for i := 0; i < b.N; i++ {
f.DomainWord()
}
}
func BenchmarkEmail(b *testing.B) {
for i := 0; i < b.N; i++ {
f.Email()
}
}
func BenchmarkFirstName(b *testing.B) {
for i := 0; i < b.N; i++ {
f.FirstName()
}
}
func BenchmarkFreeEmail(b *testing.B) {
for i := 0; i < b.N; i++ {
f.FreeEmail()
}
}
func BenchmarkJobTitle(b *testing.B) {
for i := 0; i < b.N; i++ {
f.JobTitle()
}
}
func BenchmarkLastName(b *testing.B) {
for i := 0; i < b.N; i++ {
f.LastName()
}
}
func BenchmarkName(b *testing.B) {
for i := 0; i < b.N; i++ {
f.Name()
}
}
func BenchmarkNamePrefix(b *testing.B) {
for i := 0; i < b.N; i++ {
f.NamePrefix()
}
}
func BenchmarkNameSuffix(b *testing.B) {
for i := 0; i < b.N; i++ {
f.NameSuffix()
}
}
func BenchmarkPhoneNumber(b *testing.B) {
for i := 0; i < b.N; i++ {
f.PhoneNumber()
}
}
func BenchmarkPostCode(b *testing.B) {
for i := 0; i < b.N; i++ {
f.PostCode()
}
}
func BenchmarkSafeEmail(b *testing.B) {
for i := 0; i < b.N; i++ {
f.SafeEmail()
}
}
func BenchmarkSecondaryAdress(b *testing.B) {
for i := 0; i < b.N; i++ {
f.SecondaryAddress()
}
}
func BenchmarkState(b *testing.B) {
for i := 0; i < b.N; i++ {
f.State()
}
}
func BenchmarkSateAbbr(b *testing.B) {
for i := 0; i < b.N; i++ {
f.StateAbbr()
}
}
func BenchmarkStreetAdress(b *testing.B) {
for i := 0; i < b.N; i++ {
f.StreetAddress()
}
}
func BenchmarkSteetName(b *testing.B) {
for i := 0; i < b.N; i++ {
f.StreetName()
}
}
func BenchmarkStreeSuffix(b *testing.B) {
for i := 0; i < b.N; i++ {
f.StreetSuffix()
}
}
func BenchmarkUrl(b *testing.B) {
for i := 0; i < b.N; i++ {
f.URL()
}
}
func BenchmarkUserName(b *testing.B) {
for i := 0; i < b.N; i++ {
f.UserName()
}
}