Skip to content

Commit

Permalink
Parallelise tests
Browse files Browse the repository at this point in the history
* Raise minimum required go version to 1.22
  • Loading branch information
Bios-Marcel committed Mar 3, 2024
1 parent 18fa2ae commit 8e9bed4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.22

- name: Test
run: go test -v -race -coverprofile=profile.out -covermode=atomic ./...
Expand All @@ -25,4 +25,4 @@ jobs:
uses: codecov/codecov-action@v1
with:
file: ./profile.out
fail_ci_if_error: true
fail_ci_if_error: true
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
This library allows you to substitute Discord emoji codes with their respective
emoji.

Note that the tests require golang 1.22, due to the fact that they are
parallelised, but don't shadow the loop variables.

## Example

```go
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Bios-Marcel/discordemojimap/v2

go 1.19
go 1.22.0

require github.com/stretchr/testify v1.9.0

Expand Down
20 changes: 20 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestContainsEmoji(t *testing.T) {
t.Parallel()

tests := []struct {
name string
emoji string
Expand Down Expand Up @@ -38,6 +40,8 @@ func TestContainsEmoji(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if got := ContainsEmoji(tt.emoji); got != tt.want {
t.Errorf("ContainsEmoji() = %v, want %v", got, tt.want)
}
Expand All @@ -51,6 +55,8 @@ func ExampleContainsEmoji() {
}

func TestContainsCode(t *testing.T) {
t.Parallel()

tests := []struct {
name string
emojiCode string
Expand Down Expand Up @@ -89,6 +95,8 @@ func TestContainsCode(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if got := ContainsCode(tt.emojiCode); got != tt.want {
t.Errorf("ContainsCode() = %v, want %v", got, tt.want)
}
Expand All @@ -102,6 +110,8 @@ func ExampleContainsCode() {
}

func TestGetEmojiCodes(t *testing.T) {
t.Parallel()

tests := []struct {
emoji string
want []string
Expand Down Expand Up @@ -134,6 +144,8 @@ func TestGetEmojiCodes(t *testing.T) {
}
for index, tt := range tests {
t.Run(fmt.Sprint(index), func(t *testing.T) {
t.Parallel()

if got := GetEmojiCodes(tt.emoji); !assert.ElementsMatch(t, got, tt.want) {
t.Errorf("GetEmojiCodes() = %v, want %v", got, tt.want)
}
Expand All @@ -149,6 +161,8 @@ func ExampleGetEmojiCodes() {
}

func TestGetEntriesWithPrefix(t *testing.T) {
t.Parallel()

tests := []struct {
prefix []string
want map[string]string
Expand All @@ -167,6 +181,8 @@ func TestGetEntriesWithPrefix(t *testing.T) {
}
for index, tt := range tests {
t.Run(fmt.Sprint(index), func(t *testing.T) {
t.Parallel()

for _, prefix := range tt.prefix {
if got := GetEntriesWithPrefix(prefix); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetEntriesWithPrefix() = %v, want %v", got, tt.want)
Expand All @@ -182,6 +198,8 @@ func ExampleGetEntriesWithPrefix() {
}

func TestGetEmoji(t *testing.T) {
t.Parallel()

tests := []struct {
emojiCode string
want string
Expand Down Expand Up @@ -225,6 +243,8 @@ func TestGetEmoji(t *testing.T) {
}
for index, tt := range tests {
t.Run(fmt.Sprint(index), func(t *testing.T) {
t.Parallel()

if got := GetEmoji(tt.emojiCode); got != tt.want {
t.Errorf("GetEmoji() = %v, want %v", got, tt.want)
}
Expand Down
68 changes: 37 additions & 31 deletions replacer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,39 @@ func TestReplace(t *testing.T) {
}
}

var sink string
var inputVariations = [][2]string{
{"empty string", ""},
{"just a colon", ":"},
{"empty emoji sequence", "::"},
{"invalid emoji sequence with invalid characters", ":sunglassesö:sunglasses:"},
{"valid single letter emoji sequence", ":a:"},
{"no emoji sequence", "Hello"},
{"no emoji sequence, but single colon", "Hello :"},
{"a long word", "abcdefghijklmnopqrstuvwxyz"},
{"empty emoji sequence in middle of text", "What a :: world."},
{"standalone invalid emoji sequence", ":invalidinvalid:"},
{"invalid emoji sequence with space before and after", " :invalidinvalid: "},
{"invalid emoji sequence with word before", "Hello :invalidinvalid:"},
{"invalid emoji sequence with word after", ":invalidinvalid: Hello"},
{"invalid emoji sequence with word before and after", "Hello :invalidinvalid: Hello"},
{"very long string with invalid emoji sequence in the middle", strings.Repeat("a", 1000) + ":invalidinvalid:" + strings.Repeat("b", 1000)},
{"very long string with valid emoji sequence in the middle", strings.Repeat("a", 1000) + ":sunglasses:" + strings.Repeat("b", 1000)},
{"standalone valid emoji sequence", ":sunglasses:"},
{"standalone valid uppercased emoji sequence", ":SUNGLASSES:"},
{"valid emoji sequence with word before", "hello :sunglasses:"},
{"valid emoji sequence with word before and single colon after", "Hello :sunglasses::"},
{"valid emoji sequence with word before followed by single colon and more text", "Hello :sunglasses::lol"},
{"valid emoji sequence with word after", ":sunglasses: hello"},
{"two valid emoji sequences with space inbetween", ":sunglasses: :sunglasses:"},
{"two valid emoji sequence with no space inbetween", ":sunglasses::sunglasses:"},
{"two valid emoji sequence with word inbetween", ":sunglasses: hello :sunglasses:"},
{"one mismatch", ":UPPER:"},
{"one match upper", ":CRY:"},
{"long with all kinds of cases", "I am :man_technologist: :extended_ascii_ý: :invalid_sequence: :umlautö: from :flag_for_turkey:. Tests are :thumbs_up:"},
}
var (
sink string
inputVariations = [][2]string{
{"empty string", ""},
{"just a colon", ":"},
{"empty emoji sequence", "::"},
{"invalid emoji sequence with invalid characters", ":sunglassesö:sunglasses:"},
{"valid single letter emoji sequence", ":a:"},
{"no emoji sequence", "Hello"},
{"no emoji sequence, but single colon", "Hello :"},
{"a long word", "abcdefghijklmnopqrstuvwxyz"},
{"empty emoji sequence in middle of text", "What a :: world."},
{"standalone invalid emoji sequence", ":invalidinvalid:"},
{"invalid emoji sequence with space before and after", " :invalidinvalid: "},
{"invalid emoji sequence with word before", "Hello :invalidinvalid:"},
{"invalid emoji sequence with word after", ":invalidinvalid: Hello"},
{"invalid emoji sequence with word before and after", "Hello :invalidinvalid: Hello"},
{"very long string with invalid emoji sequence in the middle", strings.Repeat("a", 1000) + ":invalidinvalid:" + strings.Repeat("b", 1000)},
{"very long string with valid emoji sequence in the middle", strings.Repeat("a", 1000) + ":sunglasses:" + strings.Repeat("b", 1000)},
{"standalone valid emoji sequence", ":sunglasses:"},
{"standalone valid uppercased emoji sequence", ":SUNGLASSES:"},
{"valid emoji sequence with word before", "hello :sunglasses:"},
{"valid emoji sequence with word before and single colon after", "Hello :sunglasses::"},
{"valid emoji sequence with word before followed by single colon and more text", "Hello :sunglasses::lol"},
{"valid emoji sequence with word after", ":sunglasses: hello"},
{"two valid emoji sequences with space inbetween", ":sunglasses: :sunglasses:"},
{"two valid emoji sequence with no space inbetween", ":sunglasses::sunglasses:"},
{"two valid emoji sequence with word inbetween", ":sunglasses: hello :sunglasses:"},
{"one mismatch", ":UPPER:"},
{"one match upper", ":CRY:"},
{"long with all kinds of cases", "I am :man_technologist: :extended_ascii_ý: :invalid_sequence: :umlautö: from :flag_for_turkey:. Tests are :thumbs_up:"},
}
)

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

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

func TestNewReplaceAndOldReplaceBehaveTheSame(t *testing.T) {
t.Parallel()

for _, test := range inputVariations {
a := oldRegexReplace(test[1])
b := Replace(test[1])
Expand Down Expand Up @@ -123,6 +127,8 @@ func BenchmarkReplace(b *testing.B) {
}

func Test_toLower(t *testing.T) {
t.Parallel()

inputs := [][2]string{
{"A", "a"},
{"a", ""},
Expand Down

0 comments on commit 8e9bed4

Please sign in to comment.