use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum DialogButtonOrder {
#[default]
#[serde(rename = "primary_right")]
PrimaryRight,
#[serde(rename = "primary_left")]
PrimaryLeft,
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
struct Wrapper {
order: DialogButtonOrder,
}
#[test]
fn serde_round_trip_both_variants() {
for (variant, expected_str) in [
(DialogButtonOrder::PrimaryRight, "primary_right"),
(DialogButtonOrder::PrimaryLeft, "primary_left"),
] {
let original = Wrapper { order: variant };
let serialized = toml::to_string(&original).unwrap();
assert!(serialized.contains(expected_str), "got: {serialized}");
let deserialized: Wrapper = toml::from_str(&serialized).unwrap();
assert_eq!(deserialized, original);
}
}
#[test]
fn deserializes_from_toml_string_values() {
for (toml_str, expected) in [
(
r#"order = "primary_right""#,
DialogButtonOrder::PrimaryRight,
),
(r#"order = "primary_left""#, DialogButtonOrder::PrimaryLeft),
] {
let w: Wrapper = toml::from_str(toml_str).unwrap();
assert_eq!(w.order, expected);
}
}
#[test]
fn debug_output_both_variants() {
assert_eq!(
format!("{:?}", DialogButtonOrder::PrimaryRight),
"PrimaryRight"
);
assert_eq!(
format!("{:?}", DialogButtonOrder::PrimaryLeft),
"PrimaryLeft"
);
}
#[test]
fn default_is_primary_right() {
assert_eq!(
DialogButtonOrder::default(),
DialogButtonOrder::PrimaryRight
);
}
}