@@ -84,6 +84,13 @@ var jsonScenarios = []formatScenario{
84
84
input : `{"cat": "meow"}` ,
85
85
expected : "D0, P[], (!!map)::cat: meow\n " ,
86
86
},
87
+ {
88
+ description : "bad json" ,
89
+ skipDoc : true ,
90
+ input : `{"a": 1 "b": 2}` ,
91
+ expectedError : `bad file 'sample.yml': invalid character '"' after object key:value pair` ,
92
+ scenarioType : "decode-error" ,
93
+ },
87
94
{
88
95
description : "Parse json: complex" ,
89
96
subdescription : "JSON is a subset of yaml, so all you need to do is prettify the output" ,
@@ -303,7 +310,13 @@ func testJSONScenario(t *testing.T, s formatScenario) {
303
310
test .AssertResultWithContext (t , s .expected , mustProcessFormatScenario (s , NewJSONDecoder (), NewJSONEncoder (0 , false , false )), s .description )
304
311
case "roundtrip-multi" :
305
312
test .AssertResultWithContext (t , s .expected , mustProcessFormatScenario (s , NewJSONDecoder (), NewJSONEncoder (2 , false , false )), s .description )
306
-
313
+ case "decode-error" :
314
+ result , err := processFormatScenario (s , NewJSONDecoder (), NewJSONEncoder (2 , false , false ))
315
+ if err == nil {
316
+ t .Errorf ("Expected error '%v' but it worked: %v" , s .expectedError , result )
317
+ } else {
318
+ test .AssertResultComplexWithContext (t , s .expectedError , err .Error (), s .description )
319
+ }
307
320
default :
308
321
panic (fmt .Sprintf ("unhandled scenario type %q" , s .scenarioType ))
309
322
}
0 commit comments