Lines
94.87 %
Functions
37.74 %
Branches
100 %
use serde::{Deserialize, Serialize};
#[test]
fn nested_untagged_enum() {
// Contributed by @caelunshun in https://github.com/ron-rs/ron/issues/217
#[derive(Debug, PartialEq, Deserialize)]
struct Root {
value: Either,
}
#[serde(transparent)]
struct Newtype(Either);
#[serde(untagged)]
enum Either {
One(One),
Two(Two),
enum One {
OneA,
OneB,
OneC,
enum Two {
TwoA,
TwoB,
TwoC,
assert_eq!(ron::de::from_str("OneA"), Ok(One::OneA));
assert_eq!(ron::de::from_str("OneA"), Ok(Either::One(One::OneA)));
assert_eq!(
ron::de::from_str("(value: OneA)"),
Ok(Root {
value: Either::One(One::OneA)
})
);
ron::de::from_str("OneA"),
Ok(Newtype(Either::One(One::OneA)))
fn untagged_enum_of_enum_list() {
// Contributed by @joonazan in https://github.com/ron-rs/ron/issues/217
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum UnitType {
Explorer,
#[derive(Serialize, Deserialize, Debug, PartialEq)]
enum CardTextNumberFlat {
JustNum(u8),
RangeW(Range_),
CountUnitW(CountUnit_),
PowerCardsPlayedW(PowerCardsPlayed),
#[allow(non_snake_case)]
struct Range_ {
Range: u8,
struct CountUnit_ {
CountUnit: Vec<UnitType>,
struct PowerCardsPlayed;
let units = CardTextNumberFlat::CountUnitW(CountUnit_ {
CountUnit: vec![UnitType::Explorer],
});
let range = CardTextNumberFlat::RangeW(Range_ { Range: 1 });
let units_ron: String = ron::to_string(&units).unwrap();
let range_ron = ron::to_string(&range).unwrap();
assert_eq!(units_ron, "(CountUnit:[Explorer])");
assert_eq!(range_ron, "(Range:1)");
let units_de: CardTextNumberFlat = ron::from_str(&units_ron).unwrap();
let range_de: CardTextNumberFlat = ron::from_str(&range_ron).unwrap();
assert_eq!(units_de, units);
assert_eq!(range_de, range);