github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/easy/ezmap/safe_test.go (about)

     1  package ezmap
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestSafeMap(t *testing.T) {
    10  	sm := NewSafeMap()
    11  
    12  	func() {
    13  		sm.Set("var1", "value1")
    14  		sm.Set("var2", 1234)
    15  	}()
    16  
    17  	assert.Equal(t, "value1", sm.MustGet("var1"))
    18  	assert.Equal(t, "value1", sm.GetString("var1"))
    19  	assert.Equal(t, 1234, sm.MustGet("var2"))
    20  	assert.Equal(t, 1234, sm.GetInt("var2"))
    21  	assert.Equal(t, int32(1234), sm.GetInt32("var2"))
    22  	assert.Equal(t, int64(1234), sm.GetInt64("var2"))
    23  }