mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Rework error messages, see #45.
This commit is contained in:
10
internal/util/reflect.go
Normal file
10
internal/util/reflect.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package util
|
||||
|
||||
import "reflect"
|
||||
|
||||
func ReflectType(v reflect.Value) reflect.Type {
|
||||
if v.Kind() != reflect.Invalid {
|
||||
return v.Type()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
21
internal/util/reflect_test.go
Normal file
21
internal/util/reflect_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReflectType(t *testing.T) {
|
||||
tests := []any{nil, 1, math.Pi, "abc"}
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprint(tt), func(t *testing.T) {
|
||||
want := fmt.Sprintf("%T", tt)
|
||||
got := fmt.Sprintf("%v", ReflectType(reflect.ValueOf(tt)))
|
||||
if got != want {
|
||||
t.Errorf("ReflectType() = %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user