css_ast/functions/
repeat_function.rs

1use super::prelude::*;
2use crate::{AutoOr, LineWidth, PositiveNonZeroInt};
3
4/// <https://drafts.csswg.org/css-gaps-1/#typedef-repeat-line-width>
5///
6/// ```text,ignore
7/// <repeat-line-width>        = repeat( [ <integer [1,∞]> ] , [ <line-width> ]+ )
8/// <auto-repeat-line-width>   = repeat( auto , [ <line-width> ]+ )
9/// ```
10#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
12#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
13pub struct RepeatFunction<'a> {
14	#[atom(CssAtomSet::Repeat)]
15	pub name: T![Function],
16	pub params: RepeatFunctionParams<'a>,
17	pub close: T![')'],
18}
19
20#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
21#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
22#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable))]
23pub struct RepeatFunctionParams<'a> {
24	#[cfg_attr(feature = "visitable", visit(skip))]
25	pub count: AutoOr<PositiveNonZeroInt>,
26	#[cfg_attr(feature = "visitable", visit(skip))]
27	pub comma: Option<T![,]>,
28	pub tracks: Vec<'a, LineWidth>,
29}
30
31#[cfg(test)]
32mod tests {
33	use super::*;
34	use crate::CssAtomSet;
35	use css_parse::{assert_parse, assert_parse_error};
36
37	#[test]
38	fn size_test() {
39		assert_eq!(std::mem::size_of::<RepeatFunction>(), 88);
40	}
41
42	#[test]
43	fn test_writes() {
44		assert_parse!(CssAtomSet::ATOMS, RepeatFunction, "repeat(2,12px)");
45		assert_parse!(CssAtomSet::ATOMS, RepeatFunction, "repeat(auto,15rem)");
46		assert_parse!(CssAtomSet::ATOMS, RepeatFunction, "repeat(2,12px 15px 18px)");
47	}
48
49	#[test]
50	fn test_errors() {
51		assert_parse_error!(CssAtomSet::ATOMS, RepeatFunction, "repeat(none, 12px)");
52	}
53}