54 lines
1.1 KiB
Go
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)
|
|
}
|