use crate::css::Css;
use crate::data_type::{CssString, Length, LengthPercentage};
use crate::keyword::{FontStyle, FontVariant, FontWeight};
use crate::value::LineHeight;
impl Css {
pub fn font_family(self, v: impl Into<String>) -> Self {
self.push("font-family", CssString::new(v))
}
pub fn font_size(self, v: impl Into<LengthPercentage>) -> Self {
self.push("font-size", v.into())
}
pub fn font_style(self, v: FontStyle) -> Self {
self.push("font-style", v)
}
pub fn font_weight(self, v: FontWeight) -> Self {
self.push("font-weight", v)
}
pub fn font_variant(self, v: FontVariant) -> Self {
self.push("font-variant", v)
}
pub fn letter_spacing(self, v: Length) -> Self {
self.push("letter-spacing", v)
}
pub fn line_height(self, v: impl Into<LineHeight>) -> Self {
self.push("line-height", v.into())
}
}
#[cfg(test)]
mod tests {
use crate::ext::*;
use crate::keyword::*;
use crate::value::LineHeight;
use crate::Css;
#[test]
fn font_family_quotes_the_value() {
let s = Css::new().font_family("Helvetica Neue");
assert_eq!(s.to_string(), "font-family: \"Helvetica Neue\";");
}
#[test]
fn font_size_length_or_percentage() {
assert_eq!(Css::new().font_size(px(16)).to_string(), "font-size: 16px;");
assert_eq!(
Css::new().font_size(percent(120)).to_string(),
"font-size: 120%;"
);
}
#[test]
fn font_style_keywords() {
assert_eq!(
Css::new().font_style(FontStyle::Italic).to_string(),
"font-style: italic;"
);
}
#[test]
fn font_weight_keyword_and_numeric() {
assert_eq!(
Css::new().font_weight(FontWeight::Bold).to_string(),
"font-weight: bold;"
);
assert_eq!(
Css::new().font_weight(FontWeight::Numeric(600)).to_string(),
"font-weight: 600;"
);
}
#[test]
fn font_variant_small_caps() {
assert_eq!(
Css::new().font_variant(FontVariant::SmallCaps).to_string(),
"font-variant: small-caps;"
);
}
#[test]
fn letter_spacing_length() {
let s = Css::new().letter_spacing(px(2));
assert_eq!(s.to_string(), "letter-spacing: 2px;");
}
#[test]
fn line_height_variants() {
assert_eq!(
Css::new().line_height(LineHeight::Normal).to_string(),
"line-height: normal;"
);
assert_eq!(
Css::new().line_height(1.5_f32).to_string(),
"line-height: 1.5;"
);
assert_eq!(
Css::new().line_height(px(24)).to_string(),
"line-height: 24px;"
);
assert_eq!(
Css::new().line_height(percent(150)).to_string(),
"line-height: 150%;"
);
}
}