css_ast/functions/
font_src_functions.rs1use super::prelude::*;
2use crate::{FontFamilyName, FontFormat, FontTech, Value};
3
4#[node]
10#[derive(Parse, Peek, ToCursors, ToSpan, 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(self))]
13#[derive(csskit_derives::NodeWithMetadata)]
14pub struct FormatFunction<'a> {
15 #[atom(CssAtomSet::Format)]
16 pub name: T![Function],
17 pub params: Value<'a, FontFormat>,
18 #[semantic_eq(skip)]
19 pub close: T![')'],
20}
21
22#[node]
28#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
30#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
31#[derive(csskit_derives::NodeWithMetadata)]
32pub struct TechFunction<'a> {
33 #[atom(CssAtomSet::Tech)]
34 pub name: T![Function],
35 pub params: CommaSeparated<'a, Value<'a, FontTech>>,
36 #[semantic_eq(skip)]
37 pub close: T![')'],
38}
39
40#[node]
46#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
47#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
48#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
49#[derive(csskit_derives::NodeWithMetadata)]
50pub struct LocalFunction<'a> {
51 #[atom(CssAtomSet::Local)]
52 pub name: T![Function],
53 pub params: FontFamilyName<'a>,
54 #[semantic_eq(skip)]
55 pub close: T![')'],
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61 use css_parse::{assert_parse, assert_parse_error};
62
63 #[test]
64 fn test_writes() {
65 assert_parse!(CssAtomSet::ATOMS, FormatFunction, "format(woff2)");
66 assert_parse!(CssAtomSet::ATOMS, FormatFunction, "format(\"woff2\")");
67 assert_parse!(CssAtomSet::ATOMS, TechFunction, "tech(variations)");
68 assert_parse!(CssAtomSet::ATOMS, TechFunction, "tech(features-opentype,color-COLRv1)");
69 assert_parse!(CssAtomSet::ATOMS, LocalFunction, "local(Gentium)");
70 assert_parse!(CssAtomSet::ATOMS, LocalFunction, "local(\"Gentium Book\")");
71 }
72
73 #[test]
74 fn test_errors() {
75 assert_parse_error!(CssAtomSet::ATOMS, FormatFunction, "format(1px)");
76 assert_parse_error!(CssAtomSet::ATOMS, TechFunction, "tech()");
77 }
78}