css_ast/rules/media/features/
device_width.rs

1use super::prelude::*;
2use crate::units::Length;
3
4ranged_feature!(
5	#[derive(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))]
8	pub enum DeviceWidthMediaFeature{CssAtomSet::DeviceWidth | CssAtomSet::MinDeviceWidth | CssAtomSet::MaxDeviceWidth, Length}
9);
10
11#[cfg(test)]
12mod tests {
13	use super::*;
14	use crate::CssAtomSet;
15	use css_parse::{assert_parse, assert_parse_error};
16
17	#[test]
18	fn size_test() {
19		assert_eq!(std::mem::size_of::<DeviceWidthMediaFeature>(), 124);
20	}
21
22	#[test]
23	fn test_writes() {
24		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width:360px)");
25		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width:35rem)");
26		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(min-device-width:35rem)");
27		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(max-device-width:35rem)");
28		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width<=800px)");
29		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width>=1400px)");
30		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width>=1400px)");
31		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width=1400px)");
32		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(1400px=device-width)");
33		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(100px<=device-width)");
34		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(100px<device-width<1400px)");
35		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(100px>device-width<1400px)");
36		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(100px>=device-width<=1400px)");
37		assert_parse!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(100px<=device-width>1400px)");
38	}
39
40	#[test]
41	fn test_errors() {
42		assert_parse_error!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width:)");
43		assert_parse_error!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width: > 10px)");
44		assert_parse_error!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(max-device-width > 10px)");
45		assert_parse_error!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(min-device-width > 10px)");
46		assert_parse_error!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width: 1%)");
47		assert_parse_error!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(device-width: 1%)");
48		assert_parse_error!(CssAtomSet::ATOMS, DeviceWidthMediaFeature, "(pointer: 1px)");
49	}
50}