-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy path465_validate_ser_identifiers.rs
89 lines (70 loc) · 2.58 KB
/
465_validate_ser_identifiers.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use serde::ser::{SerializeStruct, SerializeStructVariant, Serializer};
#[test]
fn invalid_struct_name() {
let mut ser = ron::Serializer::new(String::new(), None).unwrap();
assert_eq!(
ser.serialize_newtype_struct("", &true).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_tuple_struct("", 0).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_struct("", 0).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
}
#[test]
fn invalid_enum_variant_name() {
let mut ser = ron::Serializer::new(String::new(), None).unwrap();
assert_eq!(
ser.serialize_unit_variant("", 0, "A").err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_unit_variant("A", 0, "").err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_newtype_variant("", 0, "A", &true).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_newtype_variant("A", 0, "", &true).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_tuple_variant("", 0, "A", 0).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_tuple_variant("A", 0, "", 0).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_struct_variant("", 0, "A", 0).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
assert_eq!(
ser.serialize_struct_variant("A", 0, "", 0).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
}
#[test]
fn invalid_struct_field_name() {
let mut ser = ron::Serializer::new(String::new(), None).unwrap();
let mut r#struct = ser.serialize_struct("A", 2).unwrap();
SerializeStruct::serialize_field(&mut r#struct, "A", &true).unwrap();
assert_eq!(
SerializeStruct::serialize_field(&mut r#struct, "", &true).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
std::mem::drop(r#struct);
let mut r#struct = ser.serialize_struct_variant("A", 0, "A", 2).unwrap();
SerializeStructVariant::serialize_field(&mut r#struct, "A", &true).unwrap();
assert_eq!(
SerializeStructVariant::serialize_field(&mut r#struct, "", &true).err(),
Some(ron::Error::InvalidIdentifier(String::from(""))),
);
}