jx/internal/mapper/mapper_test.go
Matthew Rich bf79e97462
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
add mapper package
2024-08-17 18:14:54 -07:00

54 lines
1.1 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package mapper
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestNewMapper(t *testing.T) {
testMapper := New[string, int]()
assert.NotNil(t, testMapper)
}
func TestMapperGet(t *testing.T) {
testMapper := New[string, int]()
assert.NotNil(t, testMapper)
testMapper["foo"] = 3
v, exists := testMapper.Get("foo")
assert.True(t, exists)
assert.Equal(t, 3, v)
}
func TestMapperInterface(t *testing.T) {
var testInterface Map[string, int]
testMapper := New[string, int]()
assert.NotNil(t, testMapper)
testMapper["foo"] = 3
testInterface = testMapper
v, exists := testInterface.Get("foo")
assert.True(t, exists)
assert.Equal(t, 3, v)
}
func TestMapperMissing(t *testing.T) {
testMapper := New[string, int]()
assert.NotNil(t, testMapper)
testMapper["foo"] = 3
_, exists := testMapper.Get("bar")
assert.False(t, exists)
}
func TestNewStringMapper(t *testing.T) {
testMapper := NewString[int]()
assert.NotNil(t, testMapper)
testMapper["bar"] = 10
v, exists := testMapper.Get("bar")
assert.True(t, exists)
assert.Equal(t, 10, v)
}