forked from brianasapp/sputter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsputter_test.go
98 lines (77 loc) · 1.75 KB
/
sputter_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
package sputter
import (
"regexp"
"testing"
)
func TestLiteral(t *testing.T) {
testSputHundredEmoji(t, `abc`)
}
func TestCharClassSingle(t *testing.T) {
testSputHundredEmoji(t, `[A]`)
}
func TestCharClassSingleRange(t *testing.T) {
testSputHundredEmoji(t, `[0-9]`)
}
func TestCharClassMultipleRange(t *testing.T) {
testSputHundredEmoji(t, `[A-Z0-9]`)
}
func TestConcat(t *testing.T) {
testSputHundredEmoji(t, `A[0-9]`)
}
func TestExactRepeat(t *testing.T) {
testSputHundredEmoji(t, `A{5}`)
}
func TestRange(t *testing.T) {
testSputHundredEmoji(t, `A{1,5}`)
}
func TestAlternate(t *testing.T) {
testSputHundredEmoji(t, `A|B`)
}
func TestPlus(t *testing.T) {
testSputHundredEmoji(t, `A+`)
}
func TestStar(t *testing.T) {
testSputHundredEmoji(t, `A*`)
}
func TestQuest(t *testing.T) {
testSputHundredEmoji(t, `A+`)
}
func TestAnyCharNotNL(t *testing.T) {
testSputHundredEmoji(t, ".")
}
func TestBeginLine(t *testing.T) {
// testSputHundredEmoji(t, "a^a")
}
func TestEndLine(t *testing.T) {
// testSputHundredEmoji(t, "a$a")
}
func testSputHundredEmoji(t *testing.T, exp string) {
// test cryptographically secure function 100 times
for i := 0; i < 100; i++ {
s, err := Gen(exp)
if err != nil {
t.Error(`error from Gen:`, err)
}
match, err := regexp.Match(exp, []byte(s))
if !match {
t.Errorf(`output string "%s" does not match expression "%s"`, s, exp)
}
if err != nil {
t.Error(err)
}
}
// do same for cryptographically insecure function
for i := 0; i < 100; i++ {
s, err := GenInsecure(exp)
if err != nil {
t.Error(`error from Gen:`, err)
}
match, err := regexp.Match(exp, []byte(s))
if !match {
t.Errorf(`output string "%s" does not match expression "%s"`, s, exp)
}
if err != nil {
t.Error(err)
}
}
}