MCPcopy
hub / github.com/jmoiron/sqlx / TestFieldMap

Function TestFieldMap

reflectx/reflect_test.go:465–489  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

463}
464
465func TestFieldMap(t *testing.T) {
466 type Foo struct {
467 A int
468 B int
469 C int
470 }
471
472 f := Foo{1, 2, 3}
473 m := NewMapperFunc("db", strings.ToLower)
474
475 fm := m.FieldMap(reflect.ValueOf(f))
476
477 if len(fm) != 3 {
478 t.Errorf("Expecting %d keys, got %d", 3, len(fm))
479 }
480 if fm["a"].Interface().(int) != 1 {
481 t.Errorf("Expecting %d, got %d", 1, ival(fm["a"]))
482 }
483 if fm["b"].Interface().(int) != 2 {
484 t.Errorf("Expecting %d, got %d", 2, ival(fm["b"]))
485 }
486 if fm["c"].Interface().(int) != 3 {
487 t.Errorf("Expecting %d, got %d", 3, ival(fm["c"]))
488 }
489}
490
491func TestTagNameMapping(t *testing.T) {
492 type Strategy struct {

Callers

nothing calls this directly

Calls 4

NewMapperFuncFunction · 0.85
ivalFunction · 0.85
FieldMapMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected