-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
lorem_test.go
117 lines (103 loc) · 2.44 KB
/
lorem_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
package faker
import (
"fmt"
"reflect"
"strings"
"testing"
"github.com/go-faker/faker/v4/pkg/options"
"github.com/go-faker/faker/v4/pkg/slice"
)
func TestWord(t *testing.T) {
word, err := GetLorem().Word(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if !slice.Contains(wordList, word.(string)) {
t.Error("Expected word from slice wordList")
}
}
func TestSentence(t *testing.T) {
res, err := GetLorem().Sentence(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
s := res.(string)
if s == "" || !strings.HasSuffix(s, ".") {
t.Error("Expected sentence")
}
}
func TestParagraph(t *testing.T) {
res, err := GetLorem().Paragraph(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
s := res.(string)
fmt.Println(s)
if s == "" || !strings.HasSuffix(s, ".") {
t.Error("Expected paragraph")
}
}
func TestFakeWord(t *testing.T) {
word := Word()
if !slice.Contains(wordList, word) {
t.Error("Expected word from slice wordList")
}
}
func TestFakeSentence(t *testing.T) {
res := Sentence()
if res == "" || !strings.HasSuffix(res, ".") {
t.Error("Expected sentence")
}
}
func TestFakeParagraph(t *testing.T) {
res := Paragraph()
if res == "" || !strings.HasSuffix(res, ".") {
t.Error("Expected paragraph")
}
}
func TestUniqueWord(t *testing.T) {
word := Word(options.WithGenerateUniqueValues(true))
ResetUnique()
if !slice.Contains(wordList, word) {
t.Error("Expected word from slice wordList")
}
SetGenerateUniqueValues(true)
word = Word()
ResetUnique()
SetGenerateUniqueValues(false)
if !slice.Contains(wordList, word) {
t.Error("Expected word from slice wordList")
}
}
func TestUniqueWordPanic(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("expected panic, but didn't")
}
ResetUnique()
}()
length := len(wordList) + 1
for i := 0; i < length; i++ {
Word(options.WithGenerateUniqueValues(true))
}
ResetUnique()
}
func TestUniqueSentence(t *testing.T) {
res := Sentence(options.WithGenerateUniqueValues(true))
ResetUnique()
if res == "" || !strings.HasSuffix(res, ".") {
t.Error("Expected sentence")
}
}
func TestUniqueParagraph(t *testing.T) {
res := Paragraph(options.WithGenerateUniqueValues(true))
ResetUnique()
if res == "" || !strings.HasSuffix(res, ".") {
t.Error("Expected paragraph")
}
}
func BenchmarkParagraph(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = Paragraph()
}
}