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

Function TestPtrFields

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

Source from the content-addressed store, hash-verified

386}
387
388func TestPtrFields(t *testing.T) {
389 m := NewMapperTagFunc("db", strings.ToLower, nil)
390 type Asset struct {
391 Title string
392 }
393 type Post struct {
394 *Asset `db:"asset"`
395 Author string
396 }
397
398 post := &Post{Author: "Joe", Asset: &Asset{Title: "Hiyo"}}
399 pv := reflect.ValueOf(post)
400
401 fields := m.TypeMap(reflect.TypeOf(post))
402 if len(fields.Index) != 3 {
403 t.Errorf("Expecting 3 fields")
404 }
405
406 v := m.FieldByName(pv, "asset.title")
407 if v.Interface().(string) != post.Asset.Title {
408 t.Errorf("Expecting %s, got %s", post.Asset.Title, v.Interface().(string))
409 }
410 v = m.FieldByName(pv, "author")
411 if v.Interface().(string) != post.Author {
412 t.Errorf("Expecting %s, got %s", post.Author, v.Interface().(string))
413 }
414}
415
416func TestNamedPtrFields(t *testing.T) {
417 m := NewMapperTagFunc("db", strings.ToLower, nil)

Callers

nothing calls this directly

Calls 4

NewMapperTagFuncFunction · 0.85
TypeMapMethod · 0.80
ErrorfMethod · 0.80
FieldByNameMethod · 0.80

Tested by

no test coverage detected