use atom_set::AtomSet;
use derive_atom_set::AtomSet as DeriveAtomSet;
#[derive(DeriveAtomSet, Debug, Default, 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");
}
#[derive(DeriveAtomSet, Debug, Default, Clone, Copy, PartialEq, Eq)]
enum PunctuationAtomSet {
#[default]
_None,
#[atom("_")]
Underscore,
#[atom("a_b")]
ShortUnderscore,
#[atom("a[b")]
ShortBracket,
#[atom("under_score_x")]
MediumUnderscore,
#[atom("very_long_under_score_atom")]
LongUnderscore,
#[atom("café")]
NonAscii,
#[atom("abcde")]
AsciiSibling,
#[atom("ünder_score_ünder_score")]
LongNonAscii,
}
#[test]
fn matches_atoms_with_punctuation() {
assert_eq!(PunctuationAtomSet::from_str("_"), PunctuationAtomSet::Underscore);
assert_eq!(PunctuationAtomSet::from_str("a_b"), PunctuationAtomSet::ShortUnderscore);
assert_eq!(PunctuationAtomSet::from_str("a[b"), PunctuationAtomSet::ShortBracket);
assert_eq!(PunctuationAtomSet::from_str("under_score_x"), PunctuationAtomSet::MediumUnderscore);
assert_eq!(PunctuationAtomSet::from_str("very_long_under_score_atom"), PunctuationAtomSet::LongUnderscore);
assert_eq!(PunctuationAtomSet::from_str("A_B"), PunctuationAtomSet::ShortUnderscore);
assert_eq!(PunctuationAtomSet::from_str("UNDER_SCORE_X"), PunctuationAtomSet::MediumUnderscore);
assert_eq!(PunctuationAtomSet::from_str("VERY_LONG_UNDER_SCORE_ATOM"), PunctuationAtomSet::LongUnderscore);
}
#[test]
fn matches_atoms_with_non_ascii_bytes() {
assert_eq!(PunctuationAtomSet::from_str("café"), PunctuationAtomSet::NonAscii);
assert_eq!(PunctuationAtomSet::from_str("CAFé"), PunctuationAtomSet::NonAscii);
assert_eq!(PunctuationAtomSet::from_str("CAFÉ"), PunctuationAtomSet::_None);
assert_eq!(PunctuationAtomSet::from_str("abcde"), PunctuationAtomSet::AsciiSibling);
assert_eq!(PunctuationAtomSet::from_str("ABCDE"), PunctuationAtomSet::AsciiSibling);
assert_eq!(PunctuationAtomSet::from_str("ünder_score_ünder_score"), PunctuationAtomSet::LongNonAscii);
assert_eq!(PunctuationAtomSet::from_str("üNDER_SCORE_üNDER_SCORE"), PunctuationAtomSet::LongNonAscii);
}
#[test]
fn matches_atoms_with_unicode() {
assert_eq!(PunctuationAtomSet::from_str("\u{7f}"), PunctuationAtomSet::_None);
assert_eq!(PunctuationAtomSet::from_str("a\u{7f}b"), PunctuationAtomSet::_None);
assert_eq!(PunctuationAtomSet::from_str("a{b"), PunctuationAtomSet::_None);
assert_eq!(PunctuationAtomSet::from_str("under\u{7f}score\u{7f}x"), PunctuationAtomSet::_None);
assert_eq!(
PunctuationAtomSet::from_str("very\u{7f}long\u{7f}under\u{7f}score\u{7f}atom"),
PunctuationAtomSet::_None
);
}