1
use std::collections::HashMap;
2

            
3
use ron::from_str;
4
use serde::Deserialize;
5

            
6
12
#[derive(Deserialize)]
7
struct Newtype(i32);
8

            
9
12
#[derive(Deserialize)]
10
struct Tuple(i32, i32);
11

            
12
36
#[derive(Deserialize)]
13
#[allow(dead_code)]
14
struct Struct {
15
    a: i32,
16
    b: i32,
17
}
18

            
19
120
#[derive(Deserialize)]
20
#[allow(dead_code)]
21
enum Enum {
22
    Newtype(i32),
23
    Tuple(i32, i32),
24
    Struct { a: i32, b: i32 },
25
}
26

            
27
#[test]
28
4
fn test_trailing_comma_some() {
29
4
    assert!(from_str::<Option<i32>>("Some(1)").is_ok());
30
4
    assert!(from_str::<Option<i32>>("Some(1,)").is_ok());
31
4
    assert!(from_str::<Option<i32>>("Some(1,,)").is_err());
32
4
}
33

            
34
#[test]
35
4
fn test_trailing_comma_tuple() {
36
4
    assert!(from_str::<(i32, i32)>("(1,2)").is_ok());
37
4
    assert!(from_str::<(i32, i32)>("(1,2,)").is_ok());
38
4
    assert!(from_str::<(i32, i32)>("(1,2,,)").is_err());
39
4
}
40

            
41
#[test]
42
4
fn test_trailing_comma_list() {
43
4
    assert!(from_str::<Vec<i32>>("[1,2]").is_ok());
44
4
    assert!(from_str::<Vec<i32>>("[1,2,]").is_ok());
45
4
    assert!(from_str::<Vec<i32>>("[1,2,,]").is_err());
46
4
}
47

            
48
#[test]
49
4
fn test_trailing_comma_map() {
50
4
    assert!(from_str::<HashMap<i32, bool>>("{1:false,2:true}").is_ok());
51
4
    assert!(from_str::<HashMap<i32, bool>>("{1:false,2:true,}").is_ok());
52
4
    assert!(from_str::<HashMap<i32, bool>>("{1:false,2:true,,}").is_err());
53
4
}
54

            
55
#[test]
56
4
fn test_trailing_comma_newtype_struct() {
57
4
    assert!(from_str::<Newtype>("(1)").is_ok());
58
4
    assert!(from_str::<Newtype>("(1,)").is_ok());
59
4
    assert!(from_str::<Newtype>("(1,,)").is_err());
60
4
}
61

            
62
#[test]
63
4
fn test_trailing_comma_tuple_struct() {
64
4
    assert!(from_str::<Tuple>("(1,2)").is_ok());
65
4
    assert!(from_str::<Tuple>("(1,2,)").is_ok());
66
4
    assert!(from_str::<Tuple>("(1,2,,)").is_err());
67
4
}
68

            
69
#[test]
70
4
fn test_trailing_comma_struct() {
71
4
    assert!(from_str::<Struct>("(a:1,b:2)").is_ok());
72
4
    assert!(from_str::<Struct>("(a:1,b:2,)").is_ok());
73
4
    assert!(from_str::<Struct>("(a:1,b:2,,)").is_err());
74
4
}
75

            
76
#[test]
77
4
fn test_trailing_comma_enum_newtype_variant() {
78
4
    assert!(from_str::<Enum>("Newtype(1)").is_ok());
79
4
    assert!(from_str::<Enum>("Newtype(1,)").is_ok());
80
4
    assert!(from_str::<Enum>("Newtype(1,,)").is_err());
81
4
}
82

            
83
#[test]
84
4
fn test_trailing_comma_enum_tuple_variant() {
85
4
    assert!(from_str::<Enum>("Tuple(1,2)").is_ok());
86
4
    assert!(from_str::<Enum>("Tuple(1,2,)").is_ok());
87
4
    assert!(from_str::<Enum>("Tuple(1,2,,)").is_err());
88
4
}
89

            
90
#[test]
91
4
fn test_trailing_comma_enum_struct_variant() {
92
4
    assert!(from_str::<Enum>("Struct(a:1,b:2)").is_ok());
93
4
    assert!(from_str::<Enum>("Struct(a:1,b:2,)").is_ok());
94
4
    assert!(from_str::<Enum>("Struct(a:1,b:2,,)").is_err());
95
4
}