1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00
gitea/modules/util/commit_trailers_test.go

40 lines
1.3 KiB
Go
Raw Normal View History

2024-05-14 02:15:48 -04:00
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package util
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseCommitTrailerValueWithAuthor(t *testing.T) {
cases := []struct {
input string
shouldBeError bool
expectedName string
expectedEmail string
}{
{"Foo Bar <foobar@example.com", true, "", ""},
{"Foo Bar foobar@example.com>", true, "", ""},
{"Foo Bar <>", true, "", ""},
{"Foo Bar <invalid-email-address>", true, "", ""},
{"<foobar@example.com>", true, "", ""},
{" <foobar@example.com>", true, "", ""},
{"Foo Bar <foobar@example.com>", false, "Foo Bar", "foobar@example.com"},
{" Foo Bar <foobar@example.com>", false, "Foo Bar", "foobar@example.com"},
// Account for edge case where name contains an open bracket.
{" Foo < Bar <foobar@example.com>", false, "Foo < Bar", "foobar@example.com"},
}
for n, c := range cases {
name, email, err := ParseCommitTrailerValueWithAuthor(c.input)
if c.shouldBeError {
assert.Error(t, err, "case %d should be a syntax error", n)
} else {
assert.Equal(t, c.expectedName, name, "case %d should have correct name", n)
assert.Equal(t, c.expectedEmail, email, "case %d should have correct email", n)
}
}
}