css_ast/functions/
content_function.rs1use css_parse::{Function, function_set, keyword_set};
2use csskit_derives::{Parse, Peek, ToCursors, ToSpan, Visitable};
3
4function_set!(pub struct ContentFunctionName "content");
5
6#[derive(Peek, Parse, ToCursors, ToSpan, Visitable, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
13#[visit(self)]
14pub struct ContentFunction(Function<ContentFunctionName, Option<ContentKeywords>>);
15
16keyword_set!(
17 pub enum ContentKeywords {
18 Text: "text",
19 Before: "before",
20 After: "after",
21 FirstLetter: "first-letter",
22 Marker: "marker"
23 }
24);
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29 use css_parse::{assert_parse, assert_parse_error};
30
31 #[test]
32 fn size_test() {
33 assert_eq!(std::mem::size_of::<ContentFunction>(), 44);
34 assert_eq!(std::mem::size_of::<ContentKeywords>(), 16);
35 }
36
37 #[test]
38 fn test_writes() {
39 assert_parse!(ContentFunction, "content(text)");
40 assert_parse!(ContentFunction, "content(before)");
41 assert_parse!(ContentFunction, "content()");
42 }
43
44 #[test]
45 fn test_errors() {
46 assert_parse_error!(ContentFunction, "content(text before)");
47 }
48}