This commit is contained in:
Nise Void 2019-10-02 09:58:50 +02:00
parent 056b574ce1
commit 0efb52d29e
Signed by untrusted user: NiseVoid
GPG Key ID: FBA14AC83EA602F3

View File

@ -1,7 +1,7 @@
package forms
import (
"fmt"
"reflect"
"testing"
)
@ -31,10 +31,7 @@ type Anon struct {
E string
}
func TestDecode(t *testing.T) {
data := &testStruct{}
Decode(Values{
var input = Values{
`A`: {`test`},
`B`: {`10`},
`C`: {`1.25`},
@ -54,7 +51,39 @@ func TestDecode(t *testing.T) {
`SA`: {`test6`, `slice`},
`SB`: {`3`, `2`},
`SC`: {`4.50`, `1.32`},
}, data)
fmt.Println(`data:`, data, *data.PA, *data.PD)
}
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)
}
}