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