yay/vcs_test.go

66 lines
1.4 KiB
Go
Raw Normal View History

package main
2017-05-01 01:23:03 +00:00
import (
"testing"
)
2018-03-05 23:41:54 +00:00
func isEqual(a, b []string) bool {
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
2017-05-01 01:23:03 +00:00
func TestParsing(t *testing.T) {
type source struct {
2018-03-05 23:41:54 +00:00
URL string
Branch string
Protocols []string
2017-05-01 01:23:03 +00:00
}
2018-03-05 23:41:54 +00:00
urls := []string{
"git+https://github.com/neovim/neovim.git",
"git://github.com/jguer/yay.git#branch=master",
"git://github.com/davidgiven/ack",
"git://github.com/jguer/yay.git#tag=v3.440",
"git://github.com/jguer/yay.git#commit=e5470c88c6e2f9e0f97deb4728659ffa70ef5d0c",
"a+b+c+d+e+f://github.com/jguer/yay.git#branch=foo",
2017-05-01 01:23:03 +00:00
}
2018-03-05 23:41:54 +00:00
sources := []source{
2018-10-09 00:21:31 +00:00
{"github.com/neovim/neovim.git", "HEAD", []string{"https"}},
2018-03-05 23:41:54 +00:00
{"github.com/jguer/yay.git", "master", []string{"git"}},
{"github.com/davidgiven/ack", "HEAD", []string{"git"}},
{"", "", nil},
{"", "", nil},
2018-08-29 19:19:31 +00:00
{"", "", nil},
2017-05-01 01:23:03 +00:00
}
2018-03-05 23:41:54 +00:00
for n, url := range urls {
url, branch, protocols := parseSource(url)
compare := sources[n]
if url != compare.URL ||
branch != compare.Branch ||
!isEqual(protocols, compare.Protocols) {
t.Fatalf("Test %d failed: Expected: url=%+v branch=%+v protocols=%+v\ngot url=%+v branch=%+v protocols=%+v",
n+1, compare.URL, compare.Branch, compare.Protocols, url, branch, protocols)
2018-03-05 23:41:54 +00:00
}
2017-05-01 01:23:03 +00:00
}
}