unit test

This commit is contained in:
libin
2023-03-22 08:25:31 +08:00
parent 708c2166c6
commit 4b8442d00e
4 changed files with 120 additions and 121 deletions

View File

@@ -23,20 +23,22 @@ func TestIsTime(t *testing.T) {
}
func TestIsDate(t *testing.T) {
if !IsDate("2023-03-11") {
t.Error("Expected true, got false")
testCases := []struct {
input string
expected bool
}{
{"2021-01-01", true},
{"2021/01/01", false},
{"2021-13-01", false},
{"2021-02-29", false},
{"2020-02-29", true},
}
if IsDate("2023-02-29") {
t.Error("Expected false, got true")
}
if IsDate("2023-04-31") {
t.Error("Expected false, got true")
}
if IsDate("2023-13-01") {
t.Error("Expected false, got true")
}
if IsDate("2023-03-11 12:34:56") {
t.Error("Expected false, got true")
for _, testCase := range testCases {
result := IsDate(testCase.input)
if result != testCase.expected {
t.Errorf("IsDate(%v) = %v, expected %v", testCase.input, result, testCase.expected)
}
}
}