css_ast/functions/
string_function.rs1use super::prelude::*;
2
3#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
10#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
11pub struct StringFunction {
12 #[atom(CssAtomSet::String)]
13 pub name: T![Function],
14 pub params: StringFunctionParams,
15 pub close: T![')'],
16}
17
18#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
20pub struct StringFunctionParams {
21 pub ident: T![Ident],
22 pub comma: Option<T![,]>,
23 pub keyword: Option<StringKeyword>,
24}
25
26#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
27#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
28pub enum StringKeyword {
29 #[atom(CssAtomSet::First)]
30 First(T![Ident]),
31 #[atom(CssAtomSet::Start)]
32 Start(T![Ident]),
33 #[atom(CssAtomSet::Last)]
34 Last(T![Ident]),
35 #[atom(CssAtomSet::FirstExcept)]
36 FirstExcept(T![Ident]),
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42 use crate::CssAtomSet;
43 use css_parse::{assert_parse, assert_parse_error};
44
45 #[test]
46 fn size_test() {
47 assert_eq!(std::mem::size_of::<StringFunction>(), 68);
48 assert_eq!(std::mem::size_of::<StringKeyword>(), 16);
49 }
50
51 #[test]
52 fn test_writes() {
53 assert_parse!(CssAtomSet::ATOMS, StringFunction, "string(foo)");
54 assert_parse!(CssAtomSet::ATOMS, StringFunction, "string(foo,first)");
55 }
56
57 #[test]
58 fn test_errors() {
59 assert_parse_error!(CssAtomSet::ATOMS, StringFunction, "string(foo bar)");
60 }
61}