Skip to content

Commit 8e9bed4

Browse files
committed
Parallelise tests
* Raise minimum required go version to 1.22
1 parent 18fa2ae commit 8e9bed4

File tree

5 files changed

+63
-34
lines changed

5 files changed

+63
-34
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Go
1717
uses: actions/setup-go@v2
1818
with:
19-
go-version: 1.19
19+
go-version: 1.22
2020

2121
- name: Test
2222
run: go test -v -race -coverprofile=profile.out -covermode=atomic ./...
@@ -25,4 +25,4 @@ jobs:
2525
uses: codecov/codecov-action@v1
2626
with:
2727
file: ./profile.out
28-
fail_ci_if_error: true
28+
fail_ci_if_error: true

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
This library allows you to substitute Discord emoji codes with their respective
88
emoji.
99

10+
Note that the tests require golang 1.22, due to the fact that they are
11+
parallelised, but don't shadow the loop variables.
12+
1013
## Example
1114

1215
```go

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/Bios-Marcel/discordemojimap/v2
22

3-
go 1.19
3+
go 1.22.0
44

55
require github.com/stretchr/testify v1.9.0
66

query_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
)
1111

1212
func TestContainsEmoji(t *testing.T) {
13+
t.Parallel()
14+
1315
tests := []struct {
1416
name string
1517
emoji string
@@ -38,6 +40,8 @@ func TestContainsEmoji(t *testing.T) {
3840
}
3941
for _, tt := range tests {
4042
t.Run(tt.name, func(t *testing.T) {
43+
t.Parallel()
44+
4145
if got := ContainsEmoji(tt.emoji); got != tt.want {
4246
t.Errorf("ContainsEmoji() = %v, want %v", got, tt.want)
4347
}
@@ -51,6 +55,8 @@ func ExampleContainsEmoji() {
5155
}
5256

5357
func TestContainsCode(t *testing.T) {
58+
t.Parallel()
59+
5460
tests := []struct {
5561
name string
5662
emojiCode string
@@ -89,6 +95,8 @@ func TestContainsCode(t *testing.T) {
8995
}
9096
for _, tt := range tests {
9197
t.Run(tt.name, func(t *testing.T) {
98+
t.Parallel()
99+
92100
if got := ContainsCode(tt.emojiCode); got != tt.want {
93101
t.Errorf("ContainsCode() = %v, want %v", got, tt.want)
94102
}
@@ -102,6 +110,8 @@ func ExampleContainsCode() {
102110
}
103111

104112
func TestGetEmojiCodes(t *testing.T) {
113+
t.Parallel()
114+
105115
tests := []struct {
106116
emoji string
107117
want []string
@@ -134,6 +144,8 @@ func TestGetEmojiCodes(t *testing.T) {
134144
}
135145
for index, tt := range tests {
136146
t.Run(fmt.Sprint(index), func(t *testing.T) {
147+
t.Parallel()
148+
137149
if got := GetEmojiCodes(tt.emoji); !assert.ElementsMatch(t, got, tt.want) {
138150
t.Errorf("GetEmojiCodes() = %v, want %v", got, tt.want)
139151
}
@@ -149,6 +161,8 @@ func ExampleGetEmojiCodes() {
149161
}
150162

151163
func TestGetEntriesWithPrefix(t *testing.T) {
164+
t.Parallel()
165+
152166
tests := []struct {
153167
prefix []string
154168
want map[string]string
@@ -167,6 +181,8 @@ func TestGetEntriesWithPrefix(t *testing.T) {
167181
}
168182
for index, tt := range tests {
169183
t.Run(fmt.Sprint(index), func(t *testing.T) {
184+
t.Parallel()
185+
170186
for _, prefix := range tt.prefix {
171187
if got := GetEntriesWithPrefix(prefix); !reflect.DeepEqual(got, tt.want) {
172188
t.Errorf("GetEntriesWithPrefix() = %v, want %v", got, tt.want)
@@ -182,6 +198,8 @@ func ExampleGetEntriesWithPrefix() {
182198
}
183199

184200
func TestGetEmoji(t *testing.T) {
201+
t.Parallel()
202+
185203
tests := []struct {
186204
emojiCode string
187205
want string
@@ -225,6 +243,8 @@ func TestGetEmoji(t *testing.T) {
225243
}
226244
for index, tt := range tests {
227245
t.Run(fmt.Sprint(index), func(t *testing.T) {
246+
t.Parallel()
247+
228248
if got := GetEmoji(tt.emojiCode); got != tt.want {
229249
t.Errorf("GetEmoji() = %v, want %v", got, tt.want)
230250
}

replacer_test.go

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,39 @@ func TestReplace(t *testing.T) {
3434
}
3535
}
3636

37-
var sink string
38-
var inputVariations = [][2]string{
39-
{"empty string", ""},
40-
{"just a colon", ":"},
41-
{"empty emoji sequence", "::"},
42-
{"invalid emoji sequence with invalid characters", ":sunglassesö:sunglasses:"},
43-
{"valid single letter emoji sequence", ":a:"},
44-
{"no emoji sequence", "Hello"},
45-
{"no emoji sequence, but single colon", "Hello :"},
46-
{"a long word", "abcdefghijklmnopqrstuvwxyz"},
47-
{"empty emoji sequence in middle of text", "What a :: world."},
48-
{"standalone invalid emoji sequence", ":invalidinvalid:"},
49-
{"invalid emoji sequence with space before and after", " :invalidinvalid: "},
50-
{"invalid emoji sequence with word before", "Hello :invalidinvalid:"},
51-
{"invalid emoji sequence with word after", ":invalidinvalid: Hello"},
52-
{"invalid emoji sequence with word before and after", "Hello :invalidinvalid: Hello"},
53-
{"very long string with invalid emoji sequence in the middle", strings.Repeat("a", 1000) + ":invalidinvalid:" + strings.Repeat("b", 1000)},
54-
{"very long string with valid emoji sequence in the middle", strings.Repeat("a", 1000) + ":sunglasses:" + strings.Repeat("b", 1000)},
55-
{"standalone valid emoji sequence", ":sunglasses:"},
56-
{"standalone valid uppercased emoji sequence", ":SUNGLASSES:"},
57-
{"valid emoji sequence with word before", "hello :sunglasses:"},
58-
{"valid emoji sequence with word before and single colon after", "Hello :sunglasses::"},
59-
{"valid emoji sequence with word before followed by single colon and more text", "Hello :sunglasses::lol"},
60-
{"valid emoji sequence with word after", ":sunglasses: hello"},
61-
{"two valid emoji sequences with space inbetween", ":sunglasses: :sunglasses:"},
62-
{"two valid emoji sequence with no space inbetween", ":sunglasses::sunglasses:"},
63-
{"two valid emoji sequence with word inbetween", ":sunglasses: hello :sunglasses:"},
64-
{"one mismatch", ":UPPER:"},
65-
{"one match upper", ":CRY:"},
66-
{"long with all kinds of cases", "I am :man_technologist: :extended_ascii_ý: :invalid_sequence: :umlautö: from :flag_for_turkey:. Tests are :thumbs_up:"},
67-
}
37+
var (
38+
sink string
39+
inputVariations = [][2]string{
40+
{"empty string", ""},
41+
{"just a colon", ":"},
42+
{"empty emoji sequence", "::"},
43+
{"invalid emoji sequence with invalid characters", ":sunglassesö:sunglasses:"},
44+
{"valid single letter emoji sequence", ":a:"},
45+
{"no emoji sequence", "Hello"},
46+
{"no emoji sequence, but single colon", "Hello :"},
47+
{"a long word", "abcdefghijklmnopqrstuvwxyz"},
48+
{"empty emoji sequence in middle of text", "What a :: world."},
49+
{"standalone invalid emoji sequence", ":invalidinvalid:"},
50+
{"invalid emoji sequence with space before and after", " :invalidinvalid: "},
51+
{"invalid emoji sequence with word before", "Hello :invalidinvalid:"},
52+
{"invalid emoji sequence with word after", ":invalidinvalid: Hello"},
53+
{"invalid emoji sequence with word before and after", "Hello :invalidinvalid: Hello"},
54+
{"very long string with invalid emoji sequence in the middle", strings.Repeat("a", 1000) + ":invalidinvalid:" + strings.Repeat("b", 1000)},
55+
{"very long string with valid emoji sequence in the middle", strings.Repeat("a", 1000) + ":sunglasses:" + strings.Repeat("b", 1000)},
56+
{"standalone valid emoji sequence", ":sunglasses:"},
57+
{"standalone valid uppercased emoji sequence", ":SUNGLASSES:"},
58+
{"valid emoji sequence with word before", "hello :sunglasses:"},
59+
{"valid emoji sequence with word before and single colon after", "Hello :sunglasses::"},
60+
{"valid emoji sequence with word before followed by single colon and more text", "Hello :sunglasses::lol"},
61+
{"valid emoji sequence with word after", ":sunglasses: hello"},
62+
{"two valid emoji sequences with space inbetween", ":sunglasses: :sunglasses:"},
63+
{"two valid emoji sequence with no space inbetween", ":sunglasses::sunglasses:"},
64+
{"two valid emoji sequence with word inbetween", ":sunglasses: hello :sunglasses:"},
65+
{"one mismatch", ":UPPER:"},
66+
{"one match upper", ":CRY:"},
67+
{"long with all kinds of cases", "I am :man_technologist: :extended_ascii_ý: :invalid_sequence: :umlautö: from :flag_for_turkey:. Tests are :thumbs_up:"},
68+
}
69+
)
6870

6971
var emojiCodeRegex = regexp.MustCompile("(?s):[a-zA-Z0-9_]+:")
7072

@@ -87,6 +89,8 @@ func oldRegexReplace(input string) string {
8789
}
8890

8991
func TestNewReplaceAndOldReplaceBehaveTheSame(t *testing.T) {
92+
t.Parallel()
93+
9094
for _, test := range inputVariations {
9195
a := oldRegexReplace(test[1])
9296
b := Replace(test[1])
@@ -123,6 +127,8 @@ func BenchmarkReplace(b *testing.B) {
123127
}
124128

125129
func Test_toLower(t *testing.T) {
130+
t.Parallel()
131+
126132
inputs := [][2]string{
127133
{"A", "a"},
128134
{"a", ""},

0 commit comments

Comments
 (0)