css_ast/types/
ratio.rs

1use super::prelude::*;
2use crate::units::CSSInt;
3
4// https://drafts.csswg.org/css-values-4/#ratios
5#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
7#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
8#[derive(csskit_derives::NodeWithMetadata)]
9pub struct Ratio {
10	pub numerator: CSSInt,
11	pub slash: Option<T![/]>,
12	pub denominator: Option<CSSInt>,
13}
14
15#[cfg(test)]
16mod tests {
17	use super::*;
18	use crate::CssAtomSet;
19	use css_parse::{assert_parse, assert_parse_error};
20
21	#[test]
22	fn size_test() {
23		assert_eq!(std::mem::size_of::<Ratio>(), 44);
24	}
25
26	#[test]
27	fn test_writes() {
28		assert_parse!(CssAtomSet::ATOMS, Ratio, "1/1");
29		assert_parse!(CssAtomSet::ATOMS, Ratio, "5/3");
30		assert_parse!(CssAtomSet::ATOMS, Ratio, "5");
31	}
32
33	#[test]
34	fn test_errors() {
35		assert_parse_error!(CssAtomSet::ATOMS, Ratio, "5 : 3");
36		assert_parse_error!(CssAtomSet::ATOMS, Ratio, "5 / 1 / 1");
37	}
38
39	// #[cfg(feature = "serde")]
40	// #[test]
41	// fn test_serializes() {
42	// 	assert_json!(Ratio, "5/3", {
43	// 		"node": [5, 3],
44	// 		"start": 0,
45	// 		"end": 5
46	// 	});
47	// }
48}