This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
string_test.go
90 lines (68 loc) · 1.62 KB
/
string_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 iter
import (
"strings"
"testing"
"unicode/utf8"
"github.com/stretchr/testify/assert"
"mtoohey.com/iter/v2/testutils"
)
func FuzzRunes(f *testing.F) {
testutils.AddStrings(f)
f.Fuzz(func(t *testing.T, s string) {
assert.Equal(t, []rune(s), Runes(s).Collect())
})
}
func BenchmarkRunes(b *testing.B) {
buf := make([]rune, b.N)
for i := 0; i < b.N; i++ {
buf[i] = 'a'
}
str := string(buf)
Runes(str).Consume()
}
func FuzzSplitByRune(f *testing.F) {
f.Add("", ' ')
f.Add(" ", ' ')
f.Add("water", '.')
f.Add("/abs/path", '/')
f.Add("rel/path", '/')
f.Add("สวัสดีส", 'ส')
f.Add("なつ", 'つ')
f.Add("きたない", 'な')
f.Fuzz(func(t *testing.T, s string, r rune) {
if !utf8.ValidRune(r) {
return
}
assert.Equal(t, strings.Split(s, string(r)), SplitByRune(s, r).Collect())
})
}
func BenchmarkSplitByRune(b *testing.B) {
buf := make([]rune, b.N)
for i := 0; i < b.N; i++ {
buf[i] = 'a'
}
str := string(buf)
SplitByRune(str, 'a').Consume()
}
func FuzzSplitByString(f *testing.F) {
f.Add("", "")
f.Add("", " ")
f.Add(" ", " ")
f.Add("\xb0", "")
f.Add(string(utf8.RuneError), "")
f.Add("water", ".")
f.Add("[5, 9, 1, 9, 6]", ", ")
f.Add("the quick brown fox jumped over the lazy dogs", "")
f.Add("the quick brown fox jumped over the lazy dogs", "the ")
f.Fuzz(func(t *testing.T, s1, s2 string) {
assert.Equal(t, strings.Split(s1, s2), SplitByString(s1, s2).Collect())
})
}
func BenchmarkSplitByString(b *testing.B) {
buf := make([]rune, b.N)
for i := 0; i < b.N; i++ {
buf[i] = 'a'
}
str := string(buf)
SplitByString(str, "a").Consume()
}