2024-05-14 02:15:48 -04:00
|
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
2024-05-14 02:17:00 -04:00
|
|
|
|
2024-05-14 01:35:17 -04:00
|
|
|
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"},
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2024-10-26 01:48:32 -04:00
|
|
|
if err != nil {
|
|
|
|
assert.Fail(t, "did not expect an error: %v", err)
|
|
|
|
}
|
2024-05-14 01:35:17 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|