Implement fmt.Stringer for atomic types (#76)
Add safe `String()` methods for atomic types that replicate the same
behavior as `fmt.Sprintf("%v", x.Load())` without the allocations.
As with json.Marshaler/Unmarshaler, we've omitted the `atomic.Value`
type for now.
Resolves #50
This commit is contained in:
@@ -22,8 +22,10 @@ package atomic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -63,4 +65,18 @@ func TestInt64(t *testing.T) {
|
||||
assertErrorJSONUnmarshalType(t, err,
|
||||
"json.Unmarshal failed with unexpected error %v, want UnmarshalTypeError.", err)
|
||||
})
|
||||
|
||||
t.Run("String", func(t *testing.T) {
|
||||
t.Run("positive", func(t *testing.T) {
|
||||
atom := NewInt64(math.MaxInt64)
|
||||
assert.Equal(t, "9223372036854775807", atom.String(),
|
||||
"String() returned an unexpected value.")
|
||||
})
|
||||
|
||||
t.Run("negative", func(t *testing.T) {
|
||||
atom := NewInt64(math.MinInt64)
|
||||
assert.Equal(t, "-9223372036854775808", atom.String(),
|
||||
"String() returned an unexpected value.")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user