css_ast/functions/
snap_inline_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 SnapInlineFunctionName "snap-inline");
7
8#[derive(Parse, Peek, ToCursors, ToSpan, Visitable, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "kebab-case"))]
15#[visit(self)]
16pub struct SnapInlineFunction(Function<SnapInlineFunctionName, SnapInlineFunctionParams>);
17
18#[derive(Parse, Peek, ToCursors, ToSpan, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "kebab-case"))]
20pub struct SnapInlineFunctionParams(LengthPercentage, Option<T![,]>, Option<SnapInlineKeyword>, Option<T![,]>);
21
22keyword_set!(pub enum SnapInlineKeyword { Left: "left", Right: "right", Near: "near" });
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27 use css_parse::{assert_parse, assert_parse_error};
28
29 #[test]
30 fn size_test() {
31 assert_eq!(std::mem::size_of::<SnapInlineFunction>(), 92);
32 }
33
34 #[test]
35 fn test_writes() {
36 assert_parse!(SnapInlineFunction, "snap-inline(10%)");
37 assert_parse!(SnapInlineFunction, "snap-inline(10%,near)");
38 }
39
40 #[test]
41 fn test_errors() {
42 assert_parse_error!(SnapInlineFunction, "snap-block(10%)");
43 assert_parse_error!(SnapInlineFunction, "snap-inline(near)");
44 }
45}