package gapr_test import ( "testing" "code.icb4dc0.de/prskr/gapr" ) func TestGapr_Map(t *testing.T) { type args struct { input any } tests := []struct { name string args args want map[string]any wantErr bool }{ { name: "Test simple struct", args: args{ input: struct { GivenName string Surname string }{ GivenName: "Ted", Surname: "Tester", }, }, want: nil, wantErr: false, }, { name: "Test nested struct", args: args{ input: struct { GivenName string Surname string Address struct { Street string HouseNr string City string } }{ GivenName: "Ted", Surname: "Tester", Address: struct { Street string HouseNr string City string }{ Street: "Some Street", HouseNr: "3a", City: "Some City", }, }, }, want: nil, wantErr: false, }, { name: "Test simple map", args: args{ input: struct { GivenName string Surname string }{ GivenName: "Ted", Surname: "Tester", }, }, want: nil, wantErr: false, }, { name: "Test nested slice", args: args{ input: struct { GivenName string Children []struct { Name string Age uint `incomplete:"0.2,givenName"` } }{ GivenName: "Ted", Children: []struct { Name string Age uint `incomplete:"0.2,givenName"` }{ { Name: "Tim", Age: 11, }, }, }, }, want: nil, wantErr: false, }, { name: "Test map with nested struct", args: args{ input: map[string]any{ "Hello": struct { GivenName string `incomplete:"0.2,givenName"` Surname string }{ GivenName: "Ted", Surname: "Tester", }, }, }, want: nil, wantErr: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := gapr.New() got, err := g.Map(tt.args.input) if (got == nil) == (err == nil) { t.Errorf("cannot get nil value and nil error") return } if (err != nil) != tt.wantErr { t.Errorf("Map() error = %v, wantErr %v", err, tt.wantErr) return } }) } }