Feature/cover unit test (#81)

This commit is contained in:
libin
2024-07-31 19:51:01 +08:00
committed by GitHub
parent 0990bbce4d
commit a59af60d9a
60 changed files with 2571 additions and 2606 deletions

View File

@@ -1,28 +1,30 @@
package validUtil
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestIsURL(t *testing.T) {
testCases := []struct {
name string
input string
expected bool
}{
{"https://www.google.com", true},
{"http://example.com", true},
{"https://www.example.com/path?query=string", true},
{"ftp://ftp.example.com", false},
{"invalid url", false},
{"www.example.com", false},
{"example.com", false},
{"http://", false},
{"有效网址1", "https://www.google.com", true},
{"有效网址2", "http://example.com", true},
{"有效网址3", "https://www.example.com/path?query=string", true},
{"无效网址1", "ftp://ftp.example.com", false},
{"无效网址2", "invalid url", false},
{"无效网址3", "www.example.com", false},
{"无效网址4", "example.com", false},
{"无效网址5", "http://", false},
}
for _, tc := range testCases {
result := IsURL(tc.input)
if result != tc.expected {
t.Errorf("Expected IsURL(%q) to be %v, but got %v", tc.input, tc.expected, result)
}
t.Run(tc.name, func(t *testing.T) {
res := IsURL(tc.input)
assert.Equal(t, tc.expected, res)
})
}
}