2017-08-02 19:24:03 +02:00
|
|
|
package main
|
2017-05-01 03:23:03 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-03-06 00:41:54 +01:00
|
|
|
|
2020-07-23 13:53:59 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
2018-03-06 00:41:54 +01:00
|
|
|
|
2017-05-01 03:23:03 +02:00
|
|
|
func TestParsing(t *testing.T) {
|
|
|
|
type source struct {
|
2018-03-06 00:41:54 +01:00
|
|
|
URL string
|
|
|
|
Branch string
|
|
|
|
Protocols []string
|
2017-05-01 03:23:03 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 00:41:54 +01: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 03:23:03 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 00:41:54 +01:00
|
|
|
sources := []source{
|
2018-10-09 02:21:31 +02:00
|
|
|
{"github.com/neovim/neovim.git", "HEAD", []string{"https"}},
|
2018-03-06 00:41:54 +01:00
|
|
|
{"github.com/jguer/yay.git", "master", []string{"git"}},
|
|
|
|
{"github.com/davidgiven/ack", "HEAD", []string{"git"}},
|
|
|
|
{"", "", nil},
|
|
|
|
{"", "", nil},
|
2018-08-29 21:19:31 +02:00
|
|
|
{"", "", nil},
|
2017-05-01 03:23:03 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 00:41:54 +01:00
|
|
|
for n, url := range urls {
|
|
|
|
url, branch, protocols := parseSource(url)
|
|
|
|
compare := sources[n]
|
|
|
|
|
2020-07-23 13:53:59 +02:00
|
|
|
assert.Equal(t, compare.URL, url)
|
|
|
|
assert.Equal(t, compare.Branch, branch)
|
|
|
|
assert.Equal(t, compare.Protocols, protocols)
|
2017-05-01 03:23:03 +02:00
|
|
|
}
|
|
|
|
}
|