56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
|
package utils
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestIsStringInSliceOfStrings(t *testing.T) {
|
||
|
slice1 := []string{"apple", "banana", "cherry", "date"}
|
||
|
target1 := "banana"
|
||
|
result1 := IsStringInSliceOfStrings(slice1, target1)
|
||
|
expectedResult1 := true
|
||
|
if result1 != expectedResult1 {
|
||
|
t.Errorf("\ngot: %t\nwanted: %t\nfor: %q\nin: %+v", result1, expectedResult1, target1, slice1)
|
||
|
}
|
||
|
|
||
|
slice2 := []string{"apple", "banana", "cherry", "date"}
|
||
|
target2 := "grape"
|
||
|
result2 := IsStringInSliceOfStrings(slice2, target2)
|
||
|
expectedResult2 := false
|
||
|
if result2 != expectedResult2 {
|
||
|
t.Errorf("\ngot: %t\nwanted: %t\nfor: %q\nin: %+v", result2, expectedResult2, target2, slice2)
|
||
|
}
|
||
|
|
||
|
slice3 := []string{}
|
||
|
target3 := "apple"
|
||
|
result3 := IsStringInSliceOfStrings(slice3, target3)
|
||
|
expectedResult3 := false
|
||
|
if result3 != expectedResult3 {
|
||
|
t.Errorf("\ngot: %t\nwanted: %t\nfor: %q\nin: %+v", result3, expectedResult3, target3, slice3)
|
||
|
}
|
||
|
|
||
|
slice4 := []string{"pear"}
|
||
|
target4 := "pear"
|
||
|
result4 := IsStringInSliceOfStrings(slice4, target4)
|
||
|
expectedResult4 := true
|
||
|
if result4 != expectedResult4 {
|
||
|
t.Errorf("\ngot: %t\nwanted: %t\nfor: %q\nin: %+v", result4, expectedResult4, target4, slice4)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestIsValidUrl(t *testing.T) {
|
||
|
data := map[string]bool{
|
||
|
"": false,
|
||
|
"0x0001f346": false,
|
||
|
"git.0x0001f346.de": false,
|
||
|
"http://git.0x0001f346.de": true,
|
||
|
"https://git.0x0001f346.de": true,
|
||
|
"https://git.0x0001f346.de/andreas/": true,
|
||
|
}
|
||
|
|
||
|
for d, expectedResult := range data {
|
||
|
result := IsValidUrl(d)
|
||
|
if result != expectedResult {
|
||
|
t.Errorf("\ngot: %t\nwanted: %t\nfor: %q", result, expectedResult, d)
|
||
|
}
|
||
|
}
|
||
|
}
|