Skip to content

Commit

Permalink
(ast/values) properly test implemented align values
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Nov 7, 2024
1 parent cc73c86 commit c103367
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 33 deletions.
29 changes: 29 additions & 0 deletions crates/hdx_ast/src/css/values/align/impls.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
pub(crate) use crate::traits::StyleValue;
pub(crate) use hdx_proc_macro::*;

#[cfg(test)]
mod tests {
use super::super::*;
use crate::test_helpers::*;

#[test]
fn size_test() {
// assert_size!(AlignContent, 1);
// assert_size!(JustifyContent, 1);
// assert_size!(PlaceContent, 1);
// assert_size!(JustifySelf, 1);
// assert_size!(AlignSelf, 1);
// assert_size!(PlaceSelf, 1);
// assert_size!(JustifyItems, 1);
// assert_size!(AlignItems, 1);
// assert_size!(PlaceItems, 1);
assert_size!(RowGap, 8);
assert_size!(ColumnGap, 8);
assert_size!(Gap, 16);
}

#[test]
fn test_writes() {
assert_parse!(RowGap, "normal");
assert_parse!(ColumnGap, "1px");
assert_parse!(Gap, "normal 1px");
}
}
25 changes: 13 additions & 12 deletions crates/hdx_proc_macro/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,13 @@ impl Def {
let atom = ident.to_atom_macro();
let variant_name = ident.to_variant_name(0);
quote! { #atom => {
parser.hop(token);
return Ok(Self::#variant_name);
} }
} else if def == &Def::Type(DefType::CustomIdent) {
last_arm = quote! {
atom => {
parser.hop(token);
return Ok(Self::CustomIdent(atom));
}
};
Expand All @@ -464,24 +466,23 @@ impl Def {
quote! {}
}
});
if other_if.is_empty() {
let error = if other_if.is_empty() {
Some(quote! {
let token = *parser.parse::<::hdx_parser::token::Ident>()?;
match parser.parse_atom_lower(token) {
#(#keyword_arms)*
#last_arm
}
let token = parser.peek::<::hdx_parser::token::Any>().unwrap();
Err(::hdx_parser::diagnostics::Unexpected(token, token.span()))?
})
} else {
Some(quote! {
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
None
};
Some(quote! {
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
#(#keyword_arms)*
#last_arm
}
}
})
}
}
#error
})
};
if other_if.is_empty() {
quote! { #keyword_if }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl<'a> ::hdx_parser::Parse<'a> for Foo {
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("none") => {
parser.hop(token);
return Ok(Self::None);
}
atom => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl<'a> ::hdx_parser::Parse<'a> for Foo {
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("fit-content") => {
parser.hop(token);
return Ok(Self::FitContent);
}
atom => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl<'a> ::hdx_parser::Parse<'a> for Foo {
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("none") => {
parser.hop(token);
return Ok(Self::None);
}
atom => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl<'a> ::hdx_parser::Parse<'a> for Foo {
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("auto") => {
parser.hop(token);
return Ok(Self::Auto);
}
atom => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ impl<'a> ::hdx_parser::Peek<'a> for Foo {
impl<'a> ::hdx_parser::Parse<'a> for Foo {
fn parse(parser: &mut ::hdx_parser::Parser<'a>) -> ::hdx_parser::Result<Self> {
use ::hdx_parser::Parse;
let token = *parser.parse::<::hdx_parser::token::Ident>()?;
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("none") => {
return Ok(Self::None);
}
atom => {
return Ok(Self::CustomIdent(atom));
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("none") => {
parser.hop(token);
return Ok(Self::None);
}
atom => {
parser.hop(token);
return Ok(Self::CustomIdent(atom));
}
}
}
let token = parser.peek::<::hdx_parser::token::Any>().unwrap();
Err(::hdx_parser::diagnostics::Unexpected(token, token.span()))?
}
}
#[automatically_derived]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,31 @@ impl<'a> ::hdx_parser::Peek<'a> for Foo {
impl<'a> ::hdx_parser::Parse<'a> for Foo {
fn parse(parser: &mut ::hdx_parser::Parser<'a>) -> ::hdx_parser::Result<Self> {
use ::hdx_parser::Parse;
let token = *parser.parse::<::hdx_parser::token::Ident>()?;
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("black") => {
return Ok(Self::Black);
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("black") => {
parser.hop(token);
return Ok(Self::Black);
}
::hdx_atom::atom!("white") => {
parser.hop(token);
return Ok(Self::White);
}
::hdx_atom::atom!("line-through") => {
parser.hop(token);
return Ok(Self::LineThrough);
}
::hdx_atom::atom!("pink") => {
parser.hop(token);
return Ok(Self::Pink);
}
atom => {
Err(::hdx_parser::diagnostics::UnexpectedIdent(atom, token.span()))?
}
}
::hdx_atom::atom!("white") => {
return Ok(Self::White);
}
::hdx_atom::atom!("line-through") => {
return Ok(Self::LineThrough);
}
::hdx_atom::atom!("pink") => {
return Ok(Self::Pink);
}
atom => Err(::hdx_parser::diagnostics::UnexpectedIdent(atom, token.span()))?,
}
let token = parser.peek::<::hdx_parser::token::Any>().unwrap();
Err(::hdx_parser::diagnostics::Unexpected(token, token.span()))?
}
}
#[automatically_derived]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl<'a> ::hdx_parser::Parse<'a> for Foo {
if let Some(token) = parser.peek::<::hdx_parser::token::Ident>() {
match parser.parse_atom_lower(token) {
::hdx_atom::atom!("line-through") => {
parser.hop(token);
return Ok(Self::LineThrough);
}
atom => {}
Expand Down

0 comments on commit c103367

Please sign in to comment.