Files
wehub-resource-sync bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

74 lines
1.8 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package util
import "testing"
func TestIsNil(t *testing.T) {
var nilPtr *int
var nilSlice []int
var nilMap map[string]int
var nilChan chan int
var nilFunc func()
nonNilPtr := new(int)
tests := []struct {
name string
v interface{}
want bool
}{
{"nil", nil, true},
{"empty string", "", false},
{"zero int", 0, false},
{"false", false, false},
{"non-nil map", map[string]interface{}{}, false},
{"non-nil slice", []interface{}{}, false},
{"string value", "hello", false},
{"typed-nil pointer", nilPtr, true},
{"typed-nil slice", nilSlice, true},
{"typed-nil map", nilMap, true},
{"typed-nil chan", nilChan, true},
{"typed-nil func", nilFunc, true},
{"non-nil pointer", nonNilPtr, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsNil(tt.v); got != tt.want {
t.Errorf("IsNil(%v) = %v, want %v", tt.v, got, tt.want)
}
})
}
}
func TestIsEmptyValue(t *testing.T) {
tests := []struct {
name string
v interface{}
want bool
}{
{"nil", nil, true},
{"empty string", "", true},
{"non-empty string", "hello", false},
{"zero int", 0, true},
{"non-zero int", 42, false},
{"zero float64", float64(0), true},
{"non-zero float64", float64(3.14), false},
{"false", false, true},
{"true", true, false},
{"nil slice", []interface{}(nil), true},
{"empty slice", []interface{}{}, false},
{"non-empty slice", []interface{}{1}, false},
{"nil map", map[string]interface{}(nil), true},
{"empty map", map[string]interface{}{}, false},
{"non-empty map", map[string]interface{}{"a": 1}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsEmptyValue(tt.v); got != tt.want {
t.Errorf("IsEmptyValue(%v) = %v, want %v", tt.v, got, tt.want)
}
})
}
}