MCPcopy
hub / github.com/duke-git/lancet / TestToInterface

Function TestToInterface

convertor/convertor_test.go:497–526  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

495}
496
497func TestToInterface(t *testing.T) {
498 t.Parallel()
499
500 assert := internal.NewAssert(t, "TestToInterface")
501
502 cases := []reflect.Value{
503 reflect.ValueOf("abc"),
504 reflect.ValueOf(int(0)), reflect.ValueOf(int8(1)), reflect.ValueOf(int16(-1)), reflect.ValueOf(int32(123)), reflect.ValueOf(int64(123)),
505 reflect.ValueOf(uint(123)), reflect.ValueOf(uint8(123)), reflect.ValueOf(uint16(123)), reflect.ValueOf(uint32(123)), reflect.ValueOf(uint64(123)),
506 reflect.ValueOf(float64(12.3)), reflect.ValueOf(float32(12.3)),
507 reflect.ValueOf(true), reflect.ValueOf(false),
508 }
509
510 expected := []interface{}{
511 "abc",
512 0, int8(1), int16(-1), int32(123), int64(123),
513 uint(123), uint8(123), uint16(123), uint32(123), uint64(123),
514 float64(12.3), float32(12.3),
515 true, false,
516 }
517
518 for i := 0; i < len(cases); i++ {
519 actual, _ := ToInterface(cases[i])
520 assert.Equal(expected[i], actual)
521 }
522
523 nilVal, ok := ToInterface(reflect.ValueOf(nil))
524 assert.EqualValues(nil, nilVal)
525 assert.Equal(false, ok)
526}
527
528func TestUtf8ToGbk(t *testing.T) {
529 t.Parallel()

Callers

nothing calls this directly

Calls 5

EqualMethod · 0.95
EqualValuesMethod · 0.95
NewAssertFunction · 0.92
ToInterfaceFunction · 0.85
ValueOfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…