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))]
8pub struct Ratio {
9	pub numerator: CSSInt,
10	pub slash: Option<T![/]>,
11	pub denominator: Option<CSSInt>,
12}
13
14#[cfg(test)]
15mod tests {
16	use super::*;
17	use crate::CssAtomSet;
18	use css_parse::{assert_parse, assert_parse_error};
19
20	#[test]
21	fn size_test() {
22		assert_eq!(std::mem::size_of::<Ratio>(), 44);
23	}
24
25	#[test]
26	fn test_writes() {
27		assert_parse!(CssAtomSet::ATOMS, Ratio, "1/1");
28		assert_parse!(CssAtomSet::ATOMS, Ratio, "5/3");
29		assert_parse!(CssAtomSet::ATOMS, Ratio, "5");
30	}
31
32	#[test]
33	fn test_errors() {
34		assert_parse_error!(CssAtomSet::ATOMS, Ratio, "5 : 3");
35		assert_parse_error!(CssAtomSet::ATOMS, Ratio, "5 / 1 / 1");
36	}
37
38	// #[cfg(feature = "serde")]
39	// #[test]
40	// fn test_serializes() {
41	// 	assert_json!(Ratio, "5/3", {
42	// 		"node": [5, 3],
43	// 		"start": 0,
44	// 		"end": 5
45	// 	});
46	// }
47}