diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9e104a3..7598153 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 ./... @@ -25,4 +25,4 @@ jobs: uses: codecov/codecov-action@v1 with: file: ./profile.out - fail_ci_if_error: true \ No newline at end of file + fail_ci_if_error: true diff --git a/README.md b/README.md index fc4e426..bbe3f65 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/go.mod b/go.mod index 33b3304..a2543a6 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/query_test.go b/query_test.go index 322069e..23dabff 100644 --- a/query_test.go +++ b/query_test.go @@ -10,6 +10,8 @@ import ( ) func TestContainsEmoji(t *testing.T) { + t.Parallel() + tests := []struct { name string emoji string @@ -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) } @@ -51,6 +55,8 @@ func ExampleContainsEmoji() { } func TestContainsCode(t *testing.T) { + t.Parallel() + tests := []struct { name string emojiCode string @@ -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) } @@ -102,6 +110,8 @@ func ExampleContainsCode() { } func TestGetEmojiCodes(t *testing.T) { + t.Parallel() + tests := []struct { emoji string want []string @@ -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) } @@ -149,6 +161,8 @@ func ExampleGetEmojiCodes() { } func TestGetEntriesWithPrefix(t *testing.T) { + t.Parallel() + tests := []struct { prefix []string want map[string]string @@ -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) @@ -182,6 +198,8 @@ func ExampleGetEntriesWithPrefix() { } func TestGetEmoji(t *testing.T) { + t.Parallel() + tests := []struct { emojiCode string want string @@ -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) } diff --git a/replacer_test.go b/replacer_test.go index 86d25a9..41cc01e 100644 --- a/replacer_test.go +++ b/replacer_test.go @@ -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_]+:") @@ -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]) @@ -123,6 +127,8 @@ func BenchmarkReplace(b *testing.B) { } func Test_toLower(t *testing.T) { + t.Parallel() + inputs := [][2]string{ {"A", "a"}, {"a", ""},