css_ast/values/writing_modes/
impls.rs1use super::GlyphOrientationVerticalStyleValue;
2use crate::{CSSInt, CssAtomSet};
3use css_parse::{Cursor, Diagnostic, Parse, Parser, Peek, Result as ParseResult, T};
4
5impl<'a> Parse<'a> for GlyphOrientationVerticalStyleValue {
6 fn parse<I>(p: &mut Parser<'a, I>) -> ParseResult<Self>
7 where
8 I: Iterator<Item = Cursor> + Clone,
9 {
10 let c = p.peek_n(1);
11 if <T![Ident]>::peek(p, c) && p.equals_atom(c, &CssAtomSet::Auto) {
12 p.parse::<T![Ident]>().map(Self::Auto)
13 } else {
14 if let Some(int) = p.parse_if_peek::<CSSInt>()? {
15 match int.into() {
16 0i32 => {
17 return Ok(Self::Literal0(int));
18 }
19 90i32 => {
20 return Ok(Self::Literal90(int));
21 }
22 _ => {}
23 }
24 }
25 if let Some(dimension) = p.parse_if_peek::<T![Dimension]>()? {
26 match (dimension.value(), p.to_atom::<CssAtomSet>(dimension.into())) {
27 (0f32, CssAtomSet::Deg) => {
28 return Ok(Self::Literal0deg(dimension));
29 }
30 (90f32, CssAtomSet::Deg) => {
31 return Ok(Self::Literal90deg(dimension));
32 }
33 _ => {}
34 }
35 }
36 Err(Diagnostic::new(p.next(), Diagnostic::unexpected))?
37 }
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::super::*;
44 use crate::CssAtomSet;
45 use css_parse::{assert_parse, assert_parse_error};
46
47 #[test]
48 fn size_test() {
49 assert_eq!(std::mem::size_of::<DirectionStyleValue>(), 16);
50 assert_eq!(std::mem::size_of::<UnicodeBidiStyleValue>(), 16);
51 assert_eq!(std::mem::size_of::<WritingModeStyleValue>(), 16);
52 assert_eq!(std::mem::size_of::<TextOrientationStyleValue>(), 16);
53 assert_eq!(std::mem::size_of::<GlyphOrientationVerticalStyleValue>(), 16);
54 assert_eq!(std::mem::size_of::<TextCombineUprightStyleValue>(), 28);
55 }
56
57 #[test]
58 fn test_parse() {
59 assert_parse!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "auto");
60 assert_parse!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "0");
61 assert_parse!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "90");
62 assert_parse!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "90deg");
63 assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "none");
64 assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "all");
65 assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits");
66 assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 2");
67 assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 4");
68 }
69
70 #[test]
71 fn test_parse_error() {
72 assert_parse_error!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "128");
73 assert_parse_error!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "50deg");
74 assert_parse_error!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "50deg");
75 assert_parse_error!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 1");
76 assert_parse_error!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 2 2");
77 assert_parse_error!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 5");
78 }
79
80 #[cfg(feature = "css_feature_data")]
81 #[test]
82 fn test_feature_data() {
83 use crate::assert_feature_id;
84 assert_feature_id!("all", TextCombineUprightStyleValue, "css.properties.text-combine-upright.all");
85 assert_feature_id!("none", TextCombineUprightStyleValue, "css.properties.text-combine-upright.none");
86 assert_feature_id!("digits 2", TextCombineUprightStyleValue, "css.properties.text-combine-upright");
87 }
88}