61 lines
678 B
Go
61 lines
678 B
Go
package forms
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
type testStruct struct {
|
|
A string
|
|
B int
|
|
C float64
|
|
D nested
|
|
|
|
Anon
|
|
|
|
PA *string
|
|
PD *nested
|
|
|
|
SA []string
|
|
SB []int
|
|
SC []float64
|
|
}
|
|
|
|
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`},
|
|
|
|
`SA`: {`test6`, `slice`},
|
|
`SB`: {`3`, `2`},
|
|
`SC`: {`4.50`, `1.32`},
|
|
}, data)
|
|
|
|
fmt.Println(`data:`, data, *data.PA, *data.PD)
|
|
}
|