gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package git
  4. import (
  5. "testing"
  6. "time"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestParseSignatureFromCommitLine(t *testing.T) {
  10. tests := []struct {
  11. line string
  12. want *Signature
  13. }{
  14. {
  15. line: "a b <c@d.com> 12345 +0100",
  16. want: &Signature{
  17. Name: "a b",
  18. Email: "c@d.com",
  19. When: time.Unix(12345, 0).In(time.FixedZone("", 3600)),
  20. },
  21. },
  22. {
  23. line: "bad line",
  24. want: &Signature{Name: "bad line"},
  25. },
  26. {
  27. line: "bad < line",
  28. want: &Signature{Name: "bad < line"},
  29. },
  30. {
  31. line: "bad > line",
  32. want: &Signature{Name: "bad > line"},
  33. },
  34. {
  35. line: "bad-line <name@example.com>",
  36. want: &Signature{Name: "bad-line <name@example.com>"},
  37. },
  38. }
  39. for _, test := range tests {
  40. got := parseSignatureFromCommitLine(test.line)
  41. assert.Equal(t, test.want, got)
  42. }
  43. }