- The compare page head title should be `compare` but not `new pull request`. - Use `UnstableGuessRefByShortName` instead of duplicated functions calls. - Direct-compare, tags, commits compare will not display `New Pull Request` button any more. The new screenshot <img width="1459" height="391" alt="image" src="https://github.com/user-attachments/assets/64e9b070-9c0b-41d1-b4b8-233b96270e1b" /> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
106 lines
2.3 KiB
Go
106 lines
2.3 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package common
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCompareRouterReq(t *testing.T) {
|
|
cases := []struct {
|
|
input string
|
|
CompareRouterReq *CompareRouterReq
|
|
}{
|
|
{
|
|
input: "",
|
|
CompareRouterReq: &CompareRouterReq{},
|
|
},
|
|
{
|
|
input: "v1.0...v1.1",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
BaseOriRef: "v1.0",
|
|
CompareSeparator: "...",
|
|
HeadOriRef: "v1.1",
|
|
},
|
|
},
|
|
{
|
|
input: "main..develop",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
BaseOriRef: "main",
|
|
CompareSeparator: "..",
|
|
HeadOriRef: "develop",
|
|
},
|
|
},
|
|
{
|
|
input: "main^...develop",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
BaseOriRef: "main",
|
|
BaseOriRefSuffix: "^",
|
|
CompareSeparator: "...",
|
|
HeadOriRef: "develop",
|
|
},
|
|
},
|
|
{
|
|
input: "main^^^^^...develop",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
BaseOriRef: "main",
|
|
BaseOriRefSuffix: "^^^^^",
|
|
CompareSeparator: "...",
|
|
HeadOriRef: "develop",
|
|
},
|
|
},
|
|
{
|
|
input: "develop",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
CompareSeparator: "...",
|
|
HeadOriRef: "develop",
|
|
},
|
|
},
|
|
{
|
|
input: "teabot:feature1",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
CompareSeparator: "...",
|
|
HeadOwner: "teabot",
|
|
HeadOriRef: "feature1",
|
|
},
|
|
},
|
|
{
|
|
input: "lunny/forked_repo:develop",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
CompareSeparator: "...",
|
|
HeadOwner: "lunny",
|
|
HeadRepoName: "forked_repo",
|
|
HeadOriRef: "develop",
|
|
},
|
|
},
|
|
{
|
|
input: "main...lunny/forked_repo:develop",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
BaseOriRef: "main",
|
|
CompareSeparator: "...",
|
|
HeadOwner: "lunny",
|
|
HeadRepoName: "forked_repo",
|
|
HeadOriRef: "develop",
|
|
},
|
|
},
|
|
{
|
|
input: "main^...lunny/forked_repo:develop",
|
|
CompareRouterReq: &CompareRouterReq{
|
|
BaseOriRef: "main",
|
|
BaseOriRefSuffix: "^",
|
|
CompareSeparator: "...",
|
|
HeadOwner: "lunny",
|
|
HeadRepoName: "forked_repo",
|
|
HeadOriRef: "develop",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
assert.Equal(t, c.CompareRouterReq, ParseCompareRouterParam(c.input), "input: %s", c.input)
|
|
}
|
|
}
|