Skip to main content

css_ast/values/writing_modes/
impls.rs

1use super::GlyphOrientationVerticalStyleValue;
2use crate::{CSSInt, CssAtomSet, Exact, KeywordValue};
3use css_parse::{Cursor, Diagnostic, Parse, Parser, Peek, Result as ParseResult, T};
4
5impl<'a> Parse<'a> for GlyphOrientationVerticalStyleValue<'a> {
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::<KeywordValue<'a, 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(Exact(int)));
18					}
19					90i32 => {
20						return Ok(Self::Literal90(Exact(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(Exact(dimension)));
29					}
30					(90f32, CssAtomSet::Deg) => {
31						return Ok(Self::Literal90deg(Exact(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, assert_peek_false};
46
47	#[test]
48	fn test_parse() {
49		assert_parse!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "auto");
50		assert_parse!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "0");
51		assert_parse!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "90");
52		assert_parse!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "90deg");
53		assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "none");
54		assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "all");
55		assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits");
56		assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 2");
57		assert_parse!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 4");
58	}
59
60	#[test]
61	fn test_peek() {
62		assert_peek_false!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "128");
63		assert_peek_false!(CssAtomSet::ATOMS, GlyphOrientationVerticalStyleValue, "50deg");
64	}
65
66	#[test]
67	fn test_parse_error() {
68		assert_parse_error!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 1");
69		assert_parse_error!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 5");
70		assert_parse_error!(CssAtomSet::ATOMS, TextCombineUprightStyleValue, "digits 2 2");
71	}
72
73	#[cfg(feature = "css_feature_data")]
74	#[test]
75	fn test_feature_data() {
76		use crate::assert_feature_id;
77		assert_feature_id!("all", TextCombineUprightStyleValue, "css.properties.text-combine-upright.all");
78		assert_feature_id!("none", TextCombineUprightStyleValue, "css.properties.text-combine-upright.none");
79		assert_feature_id!("digits 2", TextCombineUprightStyleValue, "css.properties.text-combine-upright");
80	}
81}