@@ -70,6 +70,12 @@ enum Animal {
7070 AntHive ( Vec < String > ) ,
7171}
7272
73+ #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
74+ enum BoardGame {
75+ Chess ,
76+ Checkers ,
77+ }
78+
7379#[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
7480struct Inner {
7581 a : ( ) ,
@@ -1304,12 +1310,15 @@ fn test_parse_option() {
13041310fn test_parse_enum_errors ( ) {
13051311 test_parse_err :: < Animal > (
13061312 & [
1307- ( "{}" , "expected value at line 1 column 2" ) ,
1308- ( "[]" , "expected value at line 1 column 1" ) ,
1313+ ( "{}" , "invalid value: empty map, expected enum variant at line 1 column 1" ) ,
1314+ ( "[]" , "invalid type: sequence, expected variant identifier at line 1 column 0" ) ,
1315+ ( "true" , "invalid type: boolean `true`, expected variant identifier at line 1 column 4" ) ,
13091316 ( "\" unknown\" " ,
13101317 "unknown variant `unknown`, expected one of `Dog`, `Frog`, `Cat`, `AntHive` at line 1 column 9" ) ,
13111318 ( "{\" unknown\" :null}" ,
13121319 "unknown variant `unknown`, expected one of `Dog`, `Frog`, `Cat`, `AntHive` at line 1 column 10" ) ,
1320+ ( "{\" AntHive\" : []" , "EOF while parsing an object at line 1 column 14" ) ,
1321+ ( "{\" AntHive\" : []," , "expected `}` at line 1 column 14" ) ,
13131322 ( "{\" Dog\" :" , "EOF while parsing a value at line 1 column 7" ) ,
13141323 ( "{\" Dog\" :}" , "expected value at line 1 column 8" ) ,
13151324 ( "{\" Dog\" :{}}" , "invalid type: map, expected unit at line 1 column 7" ) ,
@@ -1331,6 +1340,40 @@ fn test_parse_enum_errors() {
13311340 ) ;
13321341}
13331342
1343+ #[ test]
1344+ fn test_parse_value_less_enum_errors ( ) {
1345+ test_parse_err :: < BoardGame > ( & [
1346+ (
1347+ "1" ,
1348+ "invalid type: integer `1`, expected variant identifier at line 1 column 1" ,
1349+ ) ,
1350+ (
1351+ "null" ,
1352+ "invalid type: null, expected variant identifier at line 1 column 4" ,
1353+ ) ,
1354+ (
1355+ "true" ,
1356+ "invalid type: boolean `true`, expected variant identifier at line 1 column 4" ,
1357+ ) ,
1358+ (
1359+ "[]" ,
1360+ "invalid type: sequence, expected variant identifier at line 1 column 0" ,
1361+ ) ,
1362+ (
1363+ "{}" ,
1364+ "invalid value: empty map, expected enum variant at line 1 column 1" ,
1365+ ) ,
1366+ (
1367+ "{\" unknown\" : \" unknown\" }" ,
1368+ "unknown variant `unknown`, expected `Chess` or `Checkers` at line 1 column 10" ,
1369+ ) ,
1370+ (
1371+ "{\" Chess\" : \" unknown\" }" ,
1372+ "invalid type: string \" unknown\" , expected unit at line 1 column 19" ,
1373+ ) ,
1374+ ] ) ;
1375+ }
1376+
13341377#[ test]
13351378fn test_parse_enum ( ) {
13361379 test_parse_ok ( vec ! [
0 commit comments