css_ast/functions/
leader_function.rs

1use super::prelude::*;
2
3/// <https://drafts.csswg.org/css-content-3/#leader-function>
4///
5/// ```text,ignore
6/// leader() = leader( <leader-type> )
7/// <leader-type> = dotted | solid | space | <string>
8/// ```
9#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
11#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
12pub struct LeaderFunction {
13	#[atom(CssAtomSet::Leader)]
14	pub name: T![Function],
15	pub params: LeaderType,
16	pub close: T![')'],
17}
18
19// https://drafts.csswg.org/css-content-3/#typedef-leader-type
20// <leader-type> = dotted | solid | space | <string>
21#[derive(Parse, Peek, IntoCursor, ToCursors, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
23pub enum LeaderType {
24	#[atom(CssAtomSet::Dotted)]
25	Dotted(T![Ident]),
26	#[atom(CssAtomSet::Solid)]
27	Solid(T![Ident]),
28	#[atom(CssAtomSet::Space)]
29	Space(T![Ident]),
30	String(T![String]),
31}
32
33#[cfg(test)]
34mod tests {
35	use super::*;
36	use crate::CssAtomSet;
37	use css_parse::{assert_parse, assert_parse_error};
38
39	#[test]
40	fn size_test() {
41		assert_eq!(std::mem::size_of::<LeaderFunction>(), 40);
42		assert_eq!(std::mem::size_of::<LeaderType>(), 16);
43	}
44
45	#[test]
46	fn test_writes() {
47		assert_parse!(CssAtomSet::ATOMS, LeaderType, "dotted");
48		assert_parse!(CssAtomSet::ATOMS, LeaderType, "'.'");
49		assert_parse!(CssAtomSet::ATOMS, LeaderType, "'abc'");
50		assert_parse!(CssAtomSet::ATOMS, LeaderFunction, "leader(dotted)");
51		assert_parse!(CssAtomSet::ATOMS, LeaderFunction, "leader('.')");
52	}
53
54	#[test]
55	fn test_errors() {
56		assert_parse_error!(CssAtomSet::ATOMS, LeaderType, "foo");
57		assert_parse_error!(CssAtomSet::ATOMS, LeaderFunction, "leader(foo)");
58	}
59}