Skip to content

Commit 10da5e0

Browse files
authored
chore: add more tests (#2801)
1 parent 4bed340 commit 10da5e0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

core/lang/lang.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Repr(v interface{}) string {
2929
}
3030

3131
val := reflect.ValueOf(v)
32-
if val.Kind() == reflect.Ptr && !val.IsNil() {
32+
for val.Kind() == reflect.Ptr && !val.IsNil() {
3333
val = val.Elem()
3434
}
3535

core/lang/lang_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package lang
22

33
import (
4+
"encoding/json"
5+
"errors"
6+
"reflect"
47
"testing"
58

69
"github.com/stretchr/testify/assert"
@@ -110,6 +113,28 @@ func TestRepr(t *testing.T) {
110113
}
111114
}
112115

116+
func TestReprOfValue(t *testing.T) {
117+
t.Run("error", func(t *testing.T) {
118+
assert.Equal(t, "error", reprOfValue(reflect.ValueOf(errors.New("error"))))
119+
})
120+
121+
t.Run("stringer", func(t *testing.T) {
122+
assert.Equal(t, "1.23", reprOfValue(reflect.ValueOf(json.Number("1.23"))))
123+
})
124+
125+
t.Run("int", func(t *testing.T) {
126+
assert.Equal(t, "1", reprOfValue(reflect.ValueOf(1)))
127+
})
128+
129+
t.Run("int", func(t *testing.T) {
130+
assert.Equal(t, "1", reprOfValue(reflect.ValueOf("1")))
131+
})
132+
133+
t.Run("int", func(t *testing.T) {
134+
assert.Equal(t, "1", reprOfValue(reflect.ValueOf(uint(1))))
135+
})
136+
}
137+
113138
type mockStringable struct{}
114139

115140
func (m mockStringable) String() string {

0 commit comments

Comments
 (0)