File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ func Repr(v interface{}) string {
29
29
}
30
30
31
31
val := reflect .ValueOf (v )
32
- if val .Kind () == reflect .Ptr && ! val .IsNil () {
32
+ for val .Kind () == reflect .Ptr && ! val .IsNil () {
33
33
val = val .Elem ()
34
34
}
35
35
Original file line number Diff line number Diff line change 1
1
package lang
2
2
3
3
import (
4
+ "encoding/json"
5
+ "errors"
6
+ "reflect"
4
7
"testing"
5
8
6
9
"github.com/stretchr/testify/assert"
@@ -110,6 +113,28 @@ func TestRepr(t *testing.T) {
110
113
}
111
114
}
112
115
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
+
113
138
type mockStringable struct {}
114
139
115
140
func (m mockStringable ) String () string {
You can’t perform that action at this time.
0 commit comments