forked from dmgk/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlorem_test.go
90 lines (80 loc) · 1.73 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
package faker
import (
"fmt"
"regexp"
"testing"
)
func TestLoremCharacters(t *testing.T) {
nums := []int{3, 17, 293}
for _, n := range nums {
for i := 0; i < 3; i++ {
res := Lorem().Characters(n)
if len(res) != n {
t.Errorf("expected %v to have len %d", res, n)
}
}
}
}
func TestLoremWord(t *testing.T) {
testMatchRx(t, Lorem().Word, `\w+`)
}
func TestLoremWords(t *testing.T) {
nums := []int{3, 17, 293}
for _, n := range nums {
for i := 0; i < 3; i++ {
res := Lorem().Words(n)
if len(res) != n {
t.Errorf("expected %v to be %d words", res, n)
}
}
}
}
func TestLoremSentence(t *testing.T) {
rx := `[A-Z]\w*\s\w+\s\w+\.`
for i := 0; i < 10; i++ {
res := Lorem().Sentence(3)
if m, _ := regexp.MatchString(rx, res); !m {
t.Errorf("expected %v to match %v", res, rx)
}
}
}
func TestLoremSentences(t *testing.T) {
nums := []int{3, 17}
for _, n := range nums {
for i := 0; i < 3; i++ {
res := Lorem().Sentences(n)
if len(res) != n {
t.Errorf("expected %v to have len %d", res, n)
}
}
}
}
func TestLoremParagraph(t *testing.T) {
rx := `[^\.]+\.[^\.]+\.[^\.]+\.`
for i := 0; i < 10; i++ {
res := Lorem().Paragraph(3)
if m, _ := regexp.MatchString(rx, res); !m {
t.Errorf("expected %v to match %v", res, rx)
}
}
}
func TestLoremParagraphs(t *testing.T) {
nums := []int{3, 17}
for _, n := range nums {
for i := 0; i < 3; i++ {
res := Lorem().Paragraphs(n)
if len(res) != n {
t.Errorf("expected %v to have len %d", res, n)
}
}
}
}
func TestLoremStringer(t *testing.T) {
rx := `^[A-Z]\w*\s[^\.]+\.$`
for i := 0; i < 10; i++ {
res := fmt.Sprintf("%s", Lorem())
if m, _ := regexp.MatchString(rx, res); !m {
t.Errorf("expected %v to match %v", res, rx)
}
}
}