From beac72e25499dab4a422c02807220c01500d9bb2 Mon Sep 17 00:00:00 2001 From: aoright <102943475+aoright@users.noreply.github.com> Date: Thu, 20 Aug 2026 13:43:32 +0800 Subject: [PATCH] test(ptr): add TestPtrHelpers and fix Int16 doc comment typo Signed-off-by: aoright <102943475+aoright@users.noreply.github.com> --- ptr/ptr.go | 2 +- ptr/ptr_test.go | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 ptr/ptr_test.go diff --git a/ptr/ptr.go b/ptr/ptr.go index d68ffed4..df2695f5 100644 --- a/ptr/ptr.go +++ b/ptr/ptr.go @@ -31,7 +31,7 @@ func Int8(x int8) *int8 { return &x } -// Int16 converts an int32 to a pointer +// Int16 converts an int16 to a pointer func Int16(x int16) *int16 { return &x } diff --git a/ptr/ptr_test.go b/ptr/ptr_test.go new file mode 100644 index 00000000..6fbc880e --- /dev/null +++ b/ptr/ptr_test.go @@ -0,0 +1,64 @@ +// Copyright (c) 2026 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package ptr + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestPtrHelpers(t *testing.T) { + t.Run("Bool", func(t *testing.T) { + assert.Equal(t, true, *Bool(true)) + assert.Equal(t, false, *Bool(false)) + }) + + t.Run("Int8", func(t *testing.T) { + val := int8(42) + assert.Equal(t, val, *Int8(val)) + }) + + t.Run("Int16", func(t *testing.T) { + val := int16(42) + assert.Equal(t, val, *Int16(val)) + }) + + t.Run("Int32", func(t *testing.T) { + val := int32(42) + assert.Equal(t, val, *Int32(val)) + }) + + t.Run("Int64", func(t *testing.T) { + val := int64(42) + assert.Equal(t, val, *Int64(val)) + }) + + t.Run("Float64", func(t *testing.T) { + val := 3.14159 + assert.Equal(t, val, *Float64(val)) + }) + + t.Run("String", func(t *testing.T) { + val := "hello" + assert.Equal(t, val, *String(val)) + }) +}