You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool/nmap/check_test.go

34 lines
812 B
Go

1 year ago
package nmap_test
import (
"git.noahlan.cn/noahlan/ntool/nmap"
"git.noahlan.cn/noahlan/ntool/ntest/assert"
"testing"
)
func TestHasKey(t *testing.T) {
var mp any = map[string]string{"key0": "val0"}
assert.True(t, nmap.HasKey(mp, "key0"))
assert.False(t, nmap.HasKey(mp, "not-exist"))
assert.False(t, nmap.HasKey("abc", "not-exist"))
}
func TestHasAllKeys(t *testing.T) {
var mp any = map[string]string{"key0": "val0", "key1": "def"}
ok, noKey := nmap.HasAllKeys(mp, "key0")
assert.True(t, ok)
assert.Nil(t, noKey)
ok, noKey = nmap.HasAllKeys(mp, "key0", "key1")
assert.True(t, ok)
assert.Nil(t, noKey)
ok, noKey = nmap.HasAllKeys(mp, "key0", "not-exist")
assert.False(t, ok)
assert.Eq(t, "not-exist", noKey)
ok, _ = nmap.HasAllKeys(mp, "invalid-map", "not-exist")
assert.False(t, ok)
}