提交 9822d1a0 编写于 作者: J johanavril

improve Project SameAs logic

use strings.EqualFold instead of strings.ToLower with equal
operation when comparing string ignore case
上级 a5fbf29b
......@@ -23,9 +23,9 @@ func (p Project) String() string {
}
func (p *Project) SameAs(other *Project) bool {
return strings.ToLower(p.Owner) == strings.ToLower(other.Owner) &&
strings.ToLower(p.Name) == strings.ToLower(other.Name) &&
strings.ToLower(p.Host) == strings.ToLower(other.Host)
return strings.EqualFold(p.Owner, other.Owner) &&
strings.EqualFold(p.Name, other.Name) &&
strings.EqualFold(p.Host, other.Host)
}
func (p *Project) WebURL(name, owner, path string) string {
......
......@@ -9,6 +9,53 @@ import (
"github.com/github/hub/fixtures"
)
func TestSameAs(t *testing.T) {
tests := []struct {
name string
project1 *Project
project2 *Project
want bool
}{
{
name: "same project",
project1: &Project{
Owner: "fOo",
Name: "baR",
Host: "gItHUb.com",
},
project2: &Project{
Owner: "FoO",
Name: "BAr",
Host: "GithUB.com",
},
want: true,
},
{
name: "different project",
project1: &Project{
Owner: "foo",
Name: "bar",
Host: "github.com",
},
project2: &Project{
Owner: "foo",
Name: "baz",
Host: "github.com",
},
want: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := test.project1.SameAs(test.project2)
want := test.want
assert.Equal(t, want, got)
})
}
}
func TestProject_WebURL(t *testing.T) {
project := Project{
Name: "foo",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册