Skip to main content

css_ast/types/
paint.rs

1use super::prelude::*;
2use crate::{Image, SvgPaint};
3
4/// <https://drafts.csswg.org/fill-stroke-3/#typedef-paint>
5///
6/// ```text,ignore
7/// <paint> = none | <image> | <svg-paint>
8/// ```
9#[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)]
13#[derive(csskit_derives::NodeWithMetadata)]
14pub enum Paint<'a> {
15	#[atom(CssAtomSet::None)]
16	None(T![Ident]),
17	Image(Image<'a>),
18	SvgPaint(SvgPaint<'a>),
19}
20
21#[cfg(test)]
22mod tests {
23	use super::*;
24	use crate::CssAtomSet;
25	use css_parse::{assert_parse, assert_peek_false};
26
27	#[test]
28	fn test_writes() {
29		assert_parse!(CssAtomSet::ATOMS, Paint, "none");
30		assert_parse!(CssAtomSet::ATOMS, Paint, "url(foo.svg)");
31		assert_parse!(CssAtomSet::ATOMS, Paint, "linear-gradient(red, blue)");
32		assert_parse!(CssAtomSet::ATOMS, Paint, "child");
33		assert_parse!(CssAtomSet::ATOMS, Paint, "child(2)");
34	}
35
36	#[test]
37	fn test_errors() {
38		assert_peek_false!(CssAtomSet::ATOMS, Paint, "");
39		// `<paint>` doesn't include `<color>` directly (that's `fill-color`'s job).
40		assert_peek_false!(CssAtomSet::ATOMS, Paint, "red");
41	}
42}