Fix test
This commit is contained in:
parent
056b574ce1
commit
0efb52d29e
@ -1,7 +1,7 @@
|
||||
package forms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -31,30 +31,59 @@ type Anon struct {
|
||||
E string
|
||||
}
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
data := &testStruct{}
|
||||
var input = Values{
|
||||
`A`: {`test`},
|
||||
`B`: {`10`},
|
||||
`C`: {`1.25`},
|
||||
|
||||
Decode(Values{
|
||||
`A`: {`test`},
|
||||
`B`: {`10`},
|
||||
`C`: {`1.25`},
|
||||
`D.A`: {`test2`},
|
||||
`D.B`: {`20`},
|
||||
`D.C`: {`2.50`},
|
||||
|
||||
`D.A`: {`test2`},
|
||||
`D.B`: {`20`},
|
||||
`D.C`: {`2.50`},
|
||||
`E`: {`test3`},
|
||||
|
||||
`E`: {`test3`},
|
||||
`PA`: {`test4`},
|
||||
|
||||
`PA`: {`test4`},
|
||||
`PD.A`: {`test5`},
|
||||
`PD.B`: {`30`},
|
||||
`PD.C`: {`3.75`},
|
||||
|
||||
`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)
|
||||
`SA`: {`test6`, `slice`},
|
||||
`SB`: {`3`, `2`},
|
||||
`SC`: {`4.50`, `1.32`},
|
||||
}
|
||||
|
||||
var expected = testStruct{
|
||||
A: `test`,
|
||||
B: 10,
|
||||
C: 1.25,
|
||||
|
||||
D: nested{A: `test2`, B: 20, C: 2.50},
|
||||
|
||||
Anon: Anon{E: `test3`},
|
||||
|
||||
SA: []string{`test6`, `slice`},
|
||||
SB: []int{3, 2},
|
||||
SC: []float64{4.50, 1.32},
|
||||
}
|
||||
|
||||
var expectedPA = `test4`
|
||||
var expectedPD = nested{`test5`, 30, 3.75}
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
data := testStruct{}
|
||||
|
||||
Decode(input, &data)
|
||||
|
||||
if *data.PA != expectedPA {
|
||||
t.Errorf(`PA was incorrect. Expected %v but got %v`, expectedPA, *data.PA)
|
||||
}
|
||||
if *data.PD != expectedPD {
|
||||
t.Errorf(`PA was incorrect. Expected %v but got %v`, expectedPD, *data.PD)
|
||||
}
|
||||
|
||||
expected.PA, expected.PD = data.PA, data.PD
|
||||
if !reflect.DeepEqual(&data, &expected) {
|
||||
t.Errorf("Data dit not match expected output. Expected \n%v\nbut got\n%v", expected, data)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user