forms/forms_test.go

61 lines
678 B
Go
Raw Normal View History

2018-12-16 15:50:35 +01:00
package forms
import (
"fmt"
"testing"
)
type testStruct struct {
A string
B int
C float64
D nested
Anon
PA *string
PD *nested
2019-10-01 16:08:20 +02:00
SA []string
SB []int
SC []float64
2018-12-16 15:50:35 +01:00
}
type nested struct {
A string
B int
C float64
}
type Anon struct {
E string
}
func TestDecode(t *testing.T) {
data := &testStruct{}
Decode(Values{
`A`: {`test`},
`B`: {`10`},
`C`: {`1.25`},
`D.A`: {`test2`},
`D.B`: {`20`},
`D.C`: {`2.50`},
`E`: {`test3`},
`PA`: {`test4`},
`PD.A`: {`test5`},
`PD.B`: {`30`},
`PD.C`: {`3.75`},
2019-10-01 16:08:20 +02:00
`SA`: {`test6`, `slice`},
`SB`: {`3`, `2`},
`SC`: {`4.50`, `1.32`},
2018-12-16 15:50:35 +01:00
}, data)
fmt.Println(`data:`, data, *data.PA, *data.PD)
}