css_ast 0.0.31

CSS Abstract Syntax Trees with visitable nodes and style value types.
Documentation
// use super::types::LengthPercentage;
// use super::{MinWidthStyleValue, Width};

// shortcuts for logical properties to resolve to 0
// impl Width {
// 	#[allow(non_upper_case_globals)]
// 	pub const Zero: Width = Width::LengthPercentage(LengthPercentage::Zero();
// }
//
// impl MinWidth {
// 	#[allow(non_upper_case_globals)]
// 	pub const Zero: MinWidth = MinWidth::LengthPercentage(LengthPercentage::Zero);
// }

#[cfg(test)]
mod tests {
	use super::super::*;
	use crate::CssAtomSet;
	use css_parse::{assert_parse, assert_parse_error, assert_peek_false};

	#[test]
	fn test_contain_intrinsic() {
		assert_parse!(CssAtomSet::ATOMS, ContainIntrinsicWidthStyleValue, "none");
		assert_parse!(CssAtomSet::ATOMS, ContainIntrinsicWidthStyleValue, "100px");
		assert_parse!(CssAtomSet::ATOMS, ContainIntrinsicWidthStyleValue, "auto none");
		assert_parse!(CssAtomSet::ATOMS, ContainIntrinsicWidthStyleValue, "auto 100px");
		assert_parse!(CssAtomSet::ATOMS, ContainIntrinsicSizeStyleValue, "none");
		assert_parse!(CssAtomSet::ATOMS, ContainIntrinsicSizeStyleValue, "100px");
		assert_parse!(CssAtomSet::ATOMS, ContainIntrinsicSizeStyleValue, "none none");
		assert_parse!(CssAtomSet::ATOMS, ContainIntrinsicSizeStyleValue, "auto none 100px");
		assert_parse_error!(CssAtomSet::ATOMS, ContainIntrinsicWidthStyleValue, "auto");
		assert_peek_false!(CssAtomSet::ATOMS, ContainIntrinsicWidthStyleValue, "");
	}

	#[test]
	fn test_min_intrinsic_sizing() {
		assert_parse!(CssAtomSet::ATOMS, MinIntrinsicSizingStyleValue, "legacy");
		assert_parse!(CssAtomSet::ATOMS, MinIntrinsicSizingStyleValue, "zero-if-scroll");
		assert_parse!(CssAtomSet::ATOMS, MinIntrinsicSizingStyleValue, "zero-if-extrinsic");
		assert_parse!(CssAtomSet::ATOMS, MinIntrinsicSizingStyleValue, "zero-if-scroll zero-if-extrinsic");
		assert_peek_false!(CssAtomSet::ATOMS, MinIntrinsicSizingStyleValue, "");
		assert_peek_false!(CssAtomSet::ATOMS, MinIntrinsicSizingStyleValue, "auto");
	}

	#[test]
	fn test_writes() {
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "0");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "1px");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "fit-content");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "fit-content(20rem)");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "fit-content(0)");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "stretch");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "contain");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "-webkit-min-content");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "-webkit-max-content");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "-moz-min-content");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "-moz-max-content");
		assert_parse!(CssAtomSet::ATOMS, HeightStyleValue, "-webkit-min-content");
		assert_parse!(CssAtomSet::ATOMS, HeightStyleValue, "-webkit-max-content");
		assert_parse!(CssAtomSet::ATOMS, HeightStyleValue, "-moz-min-content");
		assert_parse!(CssAtomSet::ATOMS, HeightStyleValue, "-moz-max-content");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "calc-size(auto, size/2)");
		assert_parse!(CssAtomSet::ATOMS, WidthStyleValue, "calc-size(any, size + 10px)");
		assert_parse!(CssAtomSet::ATOMS, HeightStyleValue, "calc-size(fit-content, size*2)");
		assert_parse!(CssAtomSet::ATOMS, MaxWidthStyleValue, "calc-size(max-content, size)");

		assert_parse!(CssAtomSet::ATOMS, AspectRatioStyleValue, "auto 1/5");
		assert_parse!(CssAtomSet::ATOMS, AspectRatioStyleValue, "auto 1/2");
		assert_parse!(CssAtomSet::ATOMS, AspectRatioStyleValue, "1/3 auto");
	}

	#[test]
	fn test_errors() {
		assert_parse_error!(CssAtomSet::ATOMS, AspectRatioStyleValue, "auto auto");
		assert_parse_error!(CssAtomSet::ATOMS, AspectRatioStyleValue, "1/2 1/2");
	}

	#[test]
	#[cfg(feature = "visitable")]
	fn test_visits() {
		use crate::assert_visits;
		assert_visits!("12px", WidthStyleValue, LengthPercentage, Length);
	}
}