Skip to main content

css_ast/functions/
light_dark_function.rs

1use super::prelude::*;
2
3/// <https://drafts.csswg.org/css-color-5/#light-dark>
4///
5/// ```text,ignore
6/// light-dark() = light-dark( <color>, <color> )
7/// ```
8#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
10#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(all))]
11#[derive(csskit_derives::NodeWithMetadata)]
12pub struct LightDarkFunction<'a> {
13	#[atom(CssAtomSet::LightDark)]
14	#[cfg_attr(feature = "visitable", visit(skip))]
15	pub name: T![Function],
16	pub light: Color<'a>,
17	#[cfg_attr(feature = "visitable", visit(skip))]
18	pub comma: T![,],
19	pub dark: Color<'a>,
20	pub close: T![')'],
21}
22
23#[cfg(test)]
24mod tests {
25	use super::*;
26	use crate::CssAtomSet;
27	use css_parse::assert_parse;
28
29	#[test]
30	fn size_test() {
31		assert_eq!(std::mem::size_of::<LightDarkFunction>(), 88);
32	}
33
34	#[test]
35	fn test_writes() {
36		assert_parse!(CssAtomSet::ATOMS, LightDarkFunction, "light-dark(red,blue)");
37		assert_parse!(CssAtomSet::ATOMS, LightDarkFunction, "light-dark(#fff,#000)");
38		assert_parse!(CssAtomSet::ATOMS, LightDarkFunction, "light-dark(rgb(255,255,255),rgb(0,0,0))");
39		assert_parse!(CssAtomSet::ATOMS, LightDarkFunction, "light-dark(white,black)");
40	}
41}