This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 148
/
lorem_test.go
111 lines (98 loc) · 2.35 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
package faker
import (
"fmt"
"reflect"
"strings"
"testing"
"github.com/bxcodec/faker/v4/pkg/options"
"github.com/bxcodec/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")
}
}