(t *testing.T)
| 255 | } |
| 256 | |
| 257 | func 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 | |
| 289 | func TestRecursiveStruct(t *testing.T) { |
| 290 | type Person struct { |
nothing calls this directly
no test coverage detected