Skip to main content

css_ast/functions/
ellipse_function.rs

1use super::prelude::*;
2use crate::{AtPosition, RadialSize};
3use css_parse::Box;
4
5/// <https://drafts.csswg.org/css-shapes/#funcdef-basic-shape-ellipse>
6///
7/// ```text,ignore
8/// <ellipse()> = ellipse(
9///   <radial-size>?
10///   [ at <position> ]?
11/// )
12/// ```
13#[node]
14#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
16#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
17#[derive(csskit_derives::NodeWithMetadata)]
18pub struct EllipseFunction<'a> {
19	#[atom(CssAtomSet::Ellipse)]
20	pub name: T![Function],
21	pub size: Option<Box<'a, RadialSize<'a>>>,
22	pub at: Option<Box<'a, AtPosition<'a>>>,
23	#[semantic_eq(skip)]
24	pub close: T![')'],
25}
26
27#[cfg(test)]
28mod tests {
29	use super::*;
30	use crate::CssAtomSet;
31	use css_parse::{assert_parse, assert_peek_false};
32
33	#[test]
34	fn test_parses() {
35		assert_parse!(CssAtomSet::ATOMS, EllipseFunction, "ellipse()");
36		assert_parse!(CssAtomSet::ATOMS, EllipseFunction, "ellipse(20px 50px)");
37		assert_parse!(CssAtomSet::ATOMS, EllipseFunction, "ellipse(4rem 50% at right center)");
38		assert_parse!(CssAtomSet::ATOMS, EllipseFunction, "ellipse(closest-side closest-side at 5rem 6rem)");
39		assert_parse!(CssAtomSet::ATOMS, EllipseFunction, "ellipse(closest-side farthest-side)");
40	}
41
42	#[test]
43	fn test_errors() {
44		assert_peek_false!(CssAtomSet::ATOMS, EllipseFunction, "circle(10px)");
45	}
46}