use derive_atom_set::AtomSet;
pub trait AtomSet {
fn from_str(s: &str) -> Self;
fn to_str(self) -> &'static str;
fn len(&self) -> u32;
fn from_bits(value: u32) -> Self;
fn as_bits(&self) -> u32;
fn is_empty(&self) -> bool {
self.len() == 0
}
}
#[derive(AtomSet, Debug, Clone, Copy, PartialEq, Eq)]
enum TestAtomSet {
#[default]
_None,
A, Px, Dpx,
Dpi, Auto, Block,
Medium, Display, Position,
Background, BorderWidth, FlexDirection, TextDecoration,
VeryLongAtomStr, ExtremelyLongAtomString, SuperLongAtomStringForTesting,
#[atom("%")]
Percentage,
}
#[test]
fn test() {
assert_eq!(TestAtomSet::from_str("a"), TestAtomSet::A);
assert_eq!(TestAtomSet::from_str("A"), TestAtomSet::A);
assert_eq!(TestAtomSet::from_str("px"), TestAtomSet::Px);
assert_eq!(TestAtomSet::from_str("dpx"), TestAtomSet::Dpx);
assert_eq!(TestAtomSet::from_str("dpi"), TestAtomSet::Dpi);
assert_eq!(TestAtomSet::from_str("auto"), TestAtomSet::Auto);
assert_eq!(TestAtomSet::from_str("block"), TestAtomSet::Block);
assert_eq!(TestAtomSet::from_str("medium"), TestAtomSet::Medium);
assert_eq!(TestAtomSet::from_str("display"), TestAtomSet::Display);
assert_eq!(TestAtomSet::from_str("position"), TestAtomSet::Position);
assert_eq!(TestAtomSet::from_str("background"), TestAtomSet::Background);
assert_eq!(TestAtomSet::from_str("border-width"), TestAtomSet::BorderWidth);
assert_eq!(TestAtomSet::from_str("flex-direction"), TestAtomSet::FlexDirection);
assert_eq!(TestAtomSet::from_str("text-decoration"), TestAtomSet::TextDecoration);
assert_eq!(TestAtomSet::from_str("very-long-atom-str"), TestAtomSet::VeryLongAtomStr);
assert_eq!(TestAtomSet::from_str("extremely-long-atom-string"), TestAtomSet::ExtremelyLongAtomString);
assert_eq!(TestAtomSet::from_str("super-long-atom-string-for-testing"), TestAtomSet::SuperLongAtomStringForTesting);
assert_eq!(TestAtomSet::from_str("BACKGROUND"), TestAtomSet::Background);
assert_eq!(TestAtomSet::from_str("VERY-LONG-ATOM-STR"), TestAtomSet::VeryLongAtomStr);
assert_eq!(TestAtomSet::from_str("SUPER-LONG-ATOM-STRING-FOR-TESTING"), TestAtomSet::SuperLongAtomStringForTesting);
assert_eq!(TestAtomSet::from_str("%"), TestAtomSet::Percentage);
assert_eq!(TestAtomSet::from_str("unknown"), TestAtomSet::_None);
assert_eq!(TestAtomSet::from_str("very-long-nonexistent-string"), TestAtomSet::_None);
assert_eq!(TestAtomSet::VeryLongAtomStr.to_str(), "very-long-atom-str");
assert_eq!(TestAtomSet::ExtremelyLongAtomString.to_str(), "extremely-long-atom-string");
assert_eq!(TestAtomSet::SuperLongAtomStringForTesting.to_str(), "super-long-atom-string-for-testing");
}