css_ast/functions/
repeat_function.rs1use crate::{AutoOr, LineWidth, PositiveNonZeroInt};
2use bumpalo::collections::Vec;
3use css_parse::{Function, T, function_set};
4use csskit_derives::{Parse, Peek, ToCursors, ToSpan, Visitable};
5
6function_set!(pub struct RepeatFunctionName "repeat");
7
8#[derive(Parse, Peek, ToCursors, ToSpan, Visitable, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
16#[visit]
17pub struct RepeatFunction<'a>(Function<RepeatFunctionName, RepeatFunctionParams<'a>>);
18
19#[derive(Parse, Peek, ToCursors, ToSpan, Visitable, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
21pub struct RepeatFunctionParams<'a> {
22 #[visit(skip)]
23 pub count: AutoOr<PositiveNonZeroInt>,
24 #[visit(skip)]
25 pub comma: Option<T![,]>,
26 pub tracks: Vec<'a, LineWidth>,
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32 use css_parse::{assert_parse, assert_parse_error};
33
34 #[test]
35 fn size_test() {
36 assert_eq!(std::mem::size_of::<RepeatFunction>(), 96);
37 }
38
39 #[test]
40 fn test_writes() {
41 assert_parse!(RepeatFunction, "repeat(2,12px)");
42 assert_parse!(RepeatFunction, "repeat(auto,15rem)");
43 assert_parse!(RepeatFunction, "repeat(2,12px 15px 18px)");
44 }
45
46 #[test]
47 fn test_errors() {
48 assert_parse_error!(RepeatFunction, "repeat(none, 12px)");
49 }
50}