diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-09-26 16:23:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-26 16:23:05 +0800 |
commit | 83a89127fdad6f551551b741c1a6967f13a02e8a (patch) | |
tree | a89002d7f4af250f3d8e517b74c7eaf478f27633 /internal/db/action_test.go | |
parent | 6ed98ca8f674d0e40d0c356df9a26fb3e2ff2cec (diff) |
action: fix issue reference regexp and error handling (#6352)
Diffstat (limited to 'internal/db/action_test.go')
-rw-r--r-- | internal/db/action_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/db/action_test.go b/internal/db/action_test.go new file mode 100644 index 00000000..afd750bb --- /dev/null +++ b/internal/db/action_test.go @@ -0,0 +1,41 @@ +// Copyright 2020 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package db + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_issueReferencePattern(t *testing.T) { + tests := []struct { + name string + message string + expStrings []string + }{ + { + name: "no match", + message: "Hello world!", + expStrings: nil, + }, + { + name: "contains issue numbers", + message: "#123 is fixed, and #456 is WIP", + expStrings: []string{"#123", " #456"}, + }, + { + name: "contains full issue references", + message: "#123 is fixed, and user/repo#456 is WIP", + expStrings: []string{"#123", " user/repo#456"}, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + strs := issueReferencePattern.FindAllString(test.message, -1) + assert.Equal(t, test.expStrings, strs) + }) + } +} |