action_test.go 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package db
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func Test_issueReferencePattern(t *testing.T) {
  10. tests := []struct {
  11. name string
  12. message string
  13. expStrings []string
  14. }{
  15. {
  16. name: "no match",
  17. message: "Hello world!",
  18. expStrings: nil,
  19. },
  20. {
  21. name: "contains issue numbers",
  22. message: "#123 is fixed, and #456 is WIP",
  23. expStrings: []string{"#123", " #456"},
  24. },
  25. {
  26. name: "contains full issue references",
  27. message: "#123 is fixed, and user/repo#456 is WIP",
  28. expStrings: []string{"#123", " user/repo#456"},
  29. },
  30. }
  31. for _, test := range tests {
  32. t.Run(test.name, func(t *testing.T) {
  33. strs := issueReferencePattern.FindAllString(test.message, -1)
  34. assert.Equal(t, test.expStrings, strs)
  35. })
  36. }
  37. }