css_ast/functions/
element_function.rs1use super::prelude::*;
2use crate::Id;
3
4#[node]
10#[derive(Parse, Peek, ToSpan, ToCursors, 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(all))]
13#[derive(csskit_derives::NodeWithMetadata)]
14pub struct ElementFunction {
15 #[atom(CssAtomSet::Element)]
16 #[cfg_attr(feature = "visitable", visit(skip))]
17 pub name: T![Function],
18 pub id: Id,
19 #[cfg_attr(feature = "visitable", visit(skip))]
20 #[semantic_eq(skip)]
21 pub close: T![')'],
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27 use crate::CssAtomSet;
28 use css_parse::{assert_parse, assert_parse_error};
29
30 #[test]
31 fn test_writes() {
32 assert_parse!(CssAtomSet::ATOMS, ElementFunction, "element(#foo)");
33 }
34
35 #[test]
36 fn test_errors() {
37 assert_parse_error!(CssAtomSet::ATOMS, ElementFunction, "element()");
38 assert_parse_error!(CssAtomSet::ATOMS, ElementFunction, "element(foo)");
39 assert_parse_error!(CssAtomSet::ATOMS, ElementFunction, "element(.foo)");
40 }
41
42 #[test]
43 #[cfg(feature = "visitable")]
44 fn test_visits() {
45 use crate::assert_visits;
46 assert_visits!("element(#foo)", ElementFunction, Id);
47 }
48}