@@ -364,7 +364,7 @@ func Test_Parse_IntType_IntOr(t *testing.T) {
364364 must .Eq (t , 100 , age )
365365}
366366
367- func Test_Parse_StringType_Strings (t * testing.T ) {
367+ func Test_Parse_StringType_Strings_present (t * testing.T ) {
368368 t .Parallel ()
369369
370370 data := url.Values {
@@ -379,3 +379,50 @@ func Test_Parse_StringType_Strings(t *testing.T) {
379379 must .NoError (t , err )
380380 must .Eq (t , []string {"alice" , "bob" , "carol" }, names )
381381}
382+
383+ func Test_Parse_StringType_Strings_missing (t * testing.T ) {
384+ t .Parallel ()
385+
386+ data := url.Values {
387+ "names" : []string {"alice" , "bob" , "carol" },
388+ }
389+
390+ var jobs []string
391+
392+ err := ParseValues (data , Schema {
393+ "jobs" : Strings (& jobs ),
394+ })
395+ must .Error (t , err )
396+ }
397+
398+ func Test_Parse_StringType_StringsOr_present (t * testing.T ) {
399+ t .Parallel ()
400+
401+ data := url.Values {
402+ "names" : []string {"alice" , "bob" , "carol" },
403+ }
404+
405+ var names []string
406+
407+ err := ParseValues (data , Schema {
408+ "names" : StringsOr (& names , []string {"zed" , "yulia" }),
409+ })
410+ must .NoError (t , err )
411+ must .Eq (t , []string {"alice" , "bob" , "carol" }, names )
412+ }
413+
414+ func Test_Parse_StringType_StringsOr_missing (t * testing.T ) {
415+ t .Parallel ()
416+
417+ data := url.Values {
418+ "names" : []string {"alice" , "bob" , "carol" },
419+ }
420+
421+ var jobs []string
422+
423+ err := ParseValues (data , Schema {
424+ "jobs" : StringsOr (& jobs , []string {"janitor" , "cashier" }),
425+ })
426+ must .NoError (t , err )
427+ must .Eq (t , []string {"janitor" , "cashier" }, jobs )
428+ }
0 commit comments