use core::fmt;
use crate::to_css::ToCss;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum FontStyle {
Normal,
Italic,
Oblique,
}
impl ToCss for FontStyle {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
FontStyle::Normal => "normal",
FontStyle::Italic => "italic",
FontStyle::Oblique => "oblique",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum FontWeight {
Normal,
Bold,
Numeric(u16),
}
impl ToCss for FontWeight {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
match self {
FontWeight::Normal => dest.write_str("normal"),
FontWeight::Bold => dest.write_str("bold"),
FontWeight::Numeric(n) => write!(dest, "{n}"),
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum FontVariant {
Normal,
SmallCaps,
}
impl ToCss for FontVariant {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
FontVariant::Normal => "normal",
FontVariant::SmallCaps => "small-caps",
})
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Cursor {
Auto,
Default,
Pointer,
Text,
None,
}
impl ToCss for Cursor {
fn to_css(&self, dest: &mut dyn fmt::Write) -> fmt::Result {
dest.write_str(match self {
Cursor::Auto => "auto",
Cursor::Default => "default",
Cursor::Pointer => "pointer",
Cursor::Text => "text",
Cursor::None => "none",
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn font_style_all() {
assert_eq!(FontStyle::Normal.to_css_string(), "normal");
assert_eq!(FontStyle::Italic.to_css_string(), "italic");
assert_eq!(FontStyle::Oblique.to_css_string(), "oblique");
}
#[test]
fn font_weight_keywords() {
assert_eq!(FontWeight::Normal.to_css_string(), "normal");
assert_eq!(FontWeight::Bold.to_css_string(), "bold");
}
#[test]
fn font_weight_numeric() {
assert_eq!(FontWeight::Numeric(100).to_css_string(), "100");
assert_eq!(FontWeight::Numeric(700).to_css_string(), "700");
assert_eq!(FontWeight::Numeric(950).to_css_string(), "950");
}
#[test]
fn font_variant_all() {
assert_eq!(FontVariant::Normal.to_css_string(), "normal");
assert_eq!(FontVariant::SmallCaps.to_css_string(), "small-caps");
}
#[test]
fn cursor_all() {
let cases = [
(Cursor::Auto, "auto"),
(Cursor::Default, "default"),
(Cursor::Pointer, "pointer"),
(Cursor::Text, "text"),
(Cursor::None, "none"),
];
for (k, expected) in cases {
assert_eq!(k.to_css_string(), expected);
}
}
}