@@ -13,6 +13,69 @@ import (
1313 "github.com/shoenig/test/must"
1414)
1515
16+ func Test_MustParse (t * testing.T ) {
17+ t .Parallel ()
18+
19+ request , err := http .NewRequestWithContext (
20+ t .Context (), http .MethodPost , "/" , nil ,
21+ )
22+ must .NoError (t , err )
23+
24+ request .PostForm = make (url.Values )
25+ request .PostForm .Set ("one" , "1" )
26+ request .PostForm .Set ("two" , "2" )
27+ request .PostForm .Set ("three" , "3.1" )
28+ request .PostForm .Set ("four" , "true" )
29+
30+ var (
31+ one string
32+ two int
33+ three float64
34+ four bool
35+ )
36+
37+ MustParse (request , Schema {
38+ "one" : String (& one ),
39+ "two" : Int (& two ),
40+ "three" : Float (& three ),
41+ "four" : Bool (& four ),
42+ })
43+ must .Eq (t , "1" , one )
44+ must .Eq (t , 2 , two )
45+ must .Eq (t , 3.1 , three )
46+ must .True (t , four )
47+ }
48+
49+ func Test_MustParse_panic (t * testing.T ) {
50+ t .Parallel ()
51+
52+ request , err := http .NewRequestWithContext (
53+ t .Context (), http .MethodPost , "/" , nil ,
54+ )
55+ must .NoError (t , err )
56+
57+ request .PostForm = make (url.Values )
58+ request .PostForm .Set ("one" , "1" )
59+ request .PostForm .Set ("three" , "3.1" )
60+ request .PostForm .Set ("four" , "true" )
61+
62+ var (
63+ one string
64+ two int
65+ three float64
66+ four bool
67+ )
68+
69+ must .Panic (t , func () {
70+ MustParse (request , Schema {
71+ "one" : String (& one ),
72+ "two" : Int (& two ),
73+ "three" : Float (& three ),
74+ "four" : Bool (& four ),
75+ })
76+ })
77+ }
78+
1679func Test_Parse_singles (t * testing.T ) {
1780 t .Parallel ()
1881
0 commit comments