css_ast/functions/
first_valid_function.rs1use super::prelude::*;
2
3#[node]
11#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
13#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit)]
14#[derive(csskit_derives::NodeWithMetadata)]
15#[metadata(declaration_kinds = Computed)]
16pub struct FirstValidFunction<'a, V> {
17 #[cfg_attr(feature = "visitable", visit(skip))]
18 #[semantic_eq(skip)]
19 #[atom(CssAtomSet::FirstValid)]
20 pub name: Function,
21 pub body: CommaSeparated<'a, V>,
22 #[cfg_attr(feature = "visitable", visit(skip))]
23 #[semantic_eq(skip)]
24 pub close: RightParen,
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use crate::{CalcableValue, CssAtomSet, Length, Value};
31 use css_parse::assert_parse;
32
33 type FirstValidLength<'a> = FirstValidFunction<'a, Value<'a, Length>>;
34 type CalcableFirstValidLength<'a> = FirstValidFunction<'a, CalcableValue<'a, Length>>;
35
36 #[test]
37 fn test_first_valid_function() {
38 assert_parse!(CssAtomSet::ATOMS, FirstValidLength, "first-valid(1px, 2em, 3rem)");
39 assert_parse!(CssAtomSet::ATOMS, FirstValidLength, "first-valid(var(--x), 10px)");
40 }
41
42 #[test]
43 fn test_calcable_first_valid_function() {
44 assert_parse!(CssAtomSet::ATOMS, CalcableFirstValidLength, "first-valid(calc(1px + 2px), 10px)");
45 }
46}