1
use serde::ser::{SerializeStruct, SerializeStructVariant, Serializer};
2

            
3
#[test]
4
4
fn invalid_struct_name() {
5
4
    let mut ser = ron::Serializer::new(String::new(), None).unwrap();
6
4

            
7
4
    assert_eq!(
8
4
        ser.serialize_newtype_struct("", &true).err(),
9
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
10
4
    );
11

            
12
4
    assert_eq!(
13
4
        ser.serialize_tuple_struct("", 0).err(),
14
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
15
4
    );
16

            
17
4
    assert_eq!(
18
4
        ser.serialize_struct("", 0).err(),
19
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
20
4
    );
21
4
}
22

            
23
#[test]
24
4
fn invalid_enum_variant_name() {
25
4
    let mut ser = ron::Serializer::new(String::new(), None).unwrap();
26
4

            
27
4
    assert_eq!(
28
4
        ser.serialize_unit_variant("", 0, "A").err(),
29
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
30
4
    );
31

            
32
4
    assert_eq!(
33
4
        ser.serialize_unit_variant("A", 0, "").err(),
34
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
35
4
    );
36

            
37
4
    assert_eq!(
38
4
        ser.serialize_newtype_variant("", 0, "A", &true).err(),
39
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
40
4
    );
41

            
42
4
    assert_eq!(
43
4
        ser.serialize_newtype_variant("A", 0, "", &true).err(),
44
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
45
4
    );
46

            
47
4
    assert_eq!(
48
4
        ser.serialize_tuple_variant("", 0, "A", 0).err(),
49
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
50
4
    );
51

            
52
4
    assert_eq!(
53
4
        ser.serialize_tuple_variant("A", 0, "", 0).err(),
54
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
55
4
    );
56

            
57
4
    assert_eq!(
58
4
        ser.serialize_struct_variant("", 0, "A", 0).err(),
59
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
60
4
    );
61

            
62
4
    assert_eq!(
63
4
        ser.serialize_struct_variant("A", 0, "", 0).err(),
64
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
65
4
    );
66
4
}
67

            
68
#[test]
69
4
fn invalid_struct_field_name() {
70
4
    let mut ser = ron::Serializer::new(String::new(), None).unwrap();
71
4

            
72
4
    let mut r#struct = ser.serialize_struct("A", 2).unwrap();
73
4
    SerializeStruct::serialize_field(&mut r#struct, "A", &true).unwrap();
74
4

            
75
4
    assert_eq!(
76
4
        SerializeStruct::serialize_field(&mut r#struct, "", &true).err(),
77
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
78
4
    );
79

            
80
4
    std::mem::drop(r#struct);
81
4

            
82
4
    let mut r#struct = ser.serialize_struct_variant("A", 0, "A", 2).unwrap();
83
4
    SerializeStructVariant::serialize_field(&mut r#struct, "A", &true).unwrap();
84
4

            
85
4
    assert_eq!(
86
4
        SerializeStructVariant::serialize_field(&mut r#struct, "", &true).err(),
87
4
        Some(ron::Error::InvalidIdentifier(String::from(""))),
88
4
    );
89
4
}