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

Function TestInlineStruct

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

Source from the content-addressed store, hash-verified

255}
256
257func TestInlineStruct(t *testing.T) {
258 m := NewMapperTagFunc("db", strings.ToLower, nil)
259
260 type Employee struct {
261 Name string
262 ID int
263 }
264 type Boss Employee
265 type person struct {
266 Employee `db:"employee"`
267 Boss `db:"boss"`
268 }
269 // employees columns: (employee.name employee.id boss.name boss.id)
270
271 em := person{Employee: Employee{Name: "Joe", ID: 2}, Boss: Boss{Name: "Dick", ID: 1}}
272 ev := reflect.ValueOf(em)
273
274 fields := m.TypeMap(reflect.TypeOf(em))
275 if len(fields.Index) != 6 {
276 t.Errorf("Expecting 6 fields")
277 }
278
279 v := m.FieldByName(ev, "employee.name")
280 if v.Interface().(string) != em.Employee.Name {
281 t.Errorf("Expecting %s, got %s", em.Employee.Name, v.Interface().(string))
282 }
283 v = m.FieldByName(ev, "boss.id")
284 if ival(v) != em.Boss.ID {
285 t.Errorf("Expecting %v, got %v", em.Boss.ID, ival(v))
286 }
287}
288
289func TestRecursiveStruct(t *testing.T) {
290 type Person struct {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected