css_ast/functions/
snap_block_function.rs1use css_parse::{Function, T, function_set, keyword_set};
2use csskit_derives::{Parse, Peek, ToCursors, ToSpan, Visitable};
3
4use crate::units::LengthPercentage;
5
6function_set!(pub struct SnapBlockFunctionName "snap-block");
7
8#[derive(Parse, Peek, ToCursors, ToSpan, Visitable, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "kebab-case"))]
12#[visit(self)]
13pub struct SnapBlockFunction(Function<SnapBlockFunctionName, SnapBlockFunctionParams>);
14
15#[derive(Parse, Peek, ToCursors, ToSpan, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "kebab-case"))]
17pub struct SnapBlockFunctionParams(LengthPercentage, Option<T![,]>, Option<SnapBlockKeyword>, Option<T![,]>);
18
19keyword_set!(pub enum SnapBlockKeyword { Start: "start", End: "end", Near: "near" });
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24 use css_parse::{assert_parse, assert_parse_error};
25
26 #[test]
27 fn size_test() {
28 assert_eq!(std::mem::size_of::<SnapBlockFunction>(), 92);
29 }
30
31 #[test]
32 fn test_writes() {
33 assert_parse!(SnapBlockFunction, "snap-block(10%)");
34 assert_parse!(SnapBlockFunction, "snap-block(10%,start)");
35 }
36
37 #[test]
38 fn test_errors() {
39 assert_parse_error!(SnapBlockFunction, "snap-inline(10%)");
40 assert_parse_error!(SnapBlockFunction, "snap-block(start)");
41 }
42}