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

Function TestBasicEmbeddedWithSameName

reflectx/reflect_test.go:153–190  ·  reflectx/reflect_test.go::TestBasicEmbeddedWithSameName
(t *testing.T)

Source from the content-addressed store, hash-verified

151}
152
153func TestBasicEmbeddedWithSameName(t *testing.T) {
154 type Foo struct {
155 A int `db:"a"`
156 Foo int `db:"Foo"` // Same name as the embedded struct
157 }
158
159 type FooExt struct {
160 Foo
161 B int `db:"b"`
162 }
163
164 m := NewMapper("db")
165
166 z := FooExt{}
167 z.A = 1
168 z.B = 2
169 z.Foo.Foo = 3
170
171 zv := reflect.ValueOf(z)
172 fields := m.TypeMap(reflect.TypeOf(z))
173
174 if len(fields.Index) != 4 {
175 t.Errorf("Expecting 3 fields, found %d", len(fields.Index))
176 }
177
178 v := m.FieldByName(zv, "a")
179 if ival(v) != z.A { // the dominant field
180 t.Errorf("Expecting %d, got %d", z.A, ival(v))
181 }
182 v = m.FieldByName(zv, "b")
183 if ival(v) != z.B {
184 t.Errorf("Expecting %d, got %d", z.B, ival(v))
185 }
186 v = m.FieldByName(zv, "Foo")
187 if ival(v) != z.Foo.Foo {
188 t.Errorf("Expecting %d, got %d", z.Foo.Foo, ival(v))
189 }
190}
191
192func TestFlatTags(t *testing.T) {
193 m := NewMapper("db")

Callers

nothing calls this directly

Calls 5

TypeMapMethod · 0.95
FieldByNameMethod · 0.95
NewMapperFunction · 0.85
ivalFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected