Skip to main content

css_ast/functions/
env_function.rs

1use super::prelude::*;
2
3/// <https://drafts.csswg.org/css-env/#env-function>
4///
5/// ```text,ignore
6/// env() = env( <custom-ident> <integer [0,∞]>*, <declaration-value>? )
7/// ```
8#[node]
9#[derive(Peek, Parse, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
11#[cfg_attr(feature = "visitable", derive(Visitable), visit)]
12#[derive(csskit_derives::NodeWithMetadata)]
13#[metadata(uses_substitution, declaration_kinds = Computed)]
14pub struct EnvFunction<'a, V> {
15	#[semantic_eq(skip)]
16	#[atom(CssAtomSet::Env)]
17	pub function: Function,
18	pub name: Ident,
19	pub dimensions: Vec<'a, CSSInt>,
20	#[semantic_eq(skip)]
21	pub comma: Option<Comma>,
22	pub fallback: Option<Box<'a, V>>,
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 EnvLength<'a> = EnvFunction<'a, Value<'a, Length>>;
34	type CalcableEnvLength<'a> = EnvFunction<'a, CalcableValue<'a, Length>>;
35
36	#[test]
37	fn test_env_function() {
38		assert_parse!(CssAtomSet::ATOMS, EnvLength, "env(safe-area-inset-top)");
39		assert_parse!(CssAtomSet::ATOMS, EnvLength, "env(safe-area-inset-top, 10px)");
40	}
41
42	#[test]
43	fn test_calcable_env_function() {
44		assert_parse!(CssAtomSet::ATOMS, CalcableEnvLength, "env(x, calc(1px + 2px))");
45	}
46}