use std::fmt::{Display, Formatter};
#[allow(clippy::upper_case_acronyms)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum AttributeValueQuotes {
DOUBLE,
SINGLE,
NONE,
}
impl AttributeValueQuotes {
pub const VALUES: [Self; 3] = [Self::DOUBLE, Self::SINGLE, Self::NONE];
#[must_use]
pub const fn ordinal(self) -> usize {
match self {
Self::DOUBLE => 0,
Self::SINGLE => 1,
Self::NONE => 2,
}
}
}
impl Display for AttributeValueQuotes {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter.write_str(match self {
Self::DOUBLE => "DOUBLE",
Self::SINGLE => "SINGLE",
Self::NONE => "NONE",
})
}
}
#[cfg(test)]
mod tests {
use super::AttributeValueQuotes;
#[test]
fn preserves_java_declaration_order_ordinals_and_names() {
assert_eq!(
AttributeValueQuotes::VALUES,
[
AttributeValueQuotes::DOUBLE,
AttributeValueQuotes::SINGLE,
AttributeValueQuotes::NONE,
]
);
for (ordinal, value) in AttributeValueQuotes::VALUES.into_iter().enumerate() {
assert_eq!(value.ordinal(), ordinal);
}
assert_eq!(AttributeValueQuotes::DOUBLE.to_string(), "DOUBLE");
assert_eq!(AttributeValueQuotes::SINGLE.to_string(), "SINGLE");
assert_eq!(AttributeValueQuotes::NONE.to_string(), "NONE");
}
}