From 86171b48f0d49edef1a97bf58e3f4962042725e0 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 17 Nov 2023 17:09:11 -0500 Subject: [PATCH] feat: parse `implementation-status` property --- moz-webgpu-cts/src/metadata.rs | 148 ++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 2 deletions(-) diff --git a/moz-webgpu-cts/src/metadata.rs b/moz-webgpu-cts/src/metadata.rs index 777d7e4..503d1df 100644 --- a/moz-webgpu-cts/src/metadata.rs +++ b/moz-webgpu-cts/src/metadata.rs @@ -61,6 +61,7 @@ pub struct FileProps { #[allow(clippy::type_complexity)] pub prefs: Option>, Vec<(String, String)>>>, pub tags: Option>, Vec>>, + pub implementation_status: Option>, ImplementationStatus>>, } impl<'a> Properties<'a> for FileProps { @@ -128,7 +129,7 @@ impl<'a> Properties<'a> for FileProps { let disabled = helper .parser( keyword("disabled").to(()), - conditional_term, + conditional_term.clone(), any() .and_is(newline().or(end()).not()) .repeated() @@ -138,7 +139,21 @@ impl<'a> Properties<'a> for FileProps { ) .map(|((), is_disabled)| FileProp::Disabled(is_disabled)); - choice((prefs, tags, disabled)) + let implementation_status = helper + .parser( + just("implementation-status").to(()), + conditional_term, + choice(( + just("backlog").to(ImplementationStatus::Backlog), + just("implementing").to(ImplementationStatus::Implementing), + just("not-implementing").to(ImplementationStatus::NotImplementing), + )), + ) + .map(|((), implementation_status)| { + FileProp::ImplementationStatus(implementation_status) + }); + + choice((prefs, tags, disabled, implementation_status)) .map_with(|prop, e| (e.span(), prop)) .boxed() } @@ -146,6 +161,7 @@ impl<'a> Properties<'a> for FileProps { fn add_property(&mut self, prop: Self::ParsedProperty, emitter: &mut Emitter>) { let (span, prop) = prop; let Self { + implementation_status, is_disabled, prefs, tags, @@ -165,6 +181,11 @@ impl<'a> Properties<'a> for FileProps { }}; } match prop { + FileProp::ImplementationStatus(new_impl_status) => check_dupe_then_insert!( + new_impl_status, + implementation_status, + "implementation-status" + ), FileProp::Prefs(new_prefs) => check_dupe_then_insert!(new_prefs, prefs, "prefs"), FileProp::Tags(new_tags) => check_dupe_then_insert!(new_tags, tags, "tags"), FileProp::Disabled(new_is_disabled) => { @@ -319,6 +340,87 @@ fn file_props() { "### ); + insta::assert_debug_snapshot!( + parser.parse("implementation-status: default"), + @r###" + ParseResult { + output: None, + errs: [ + found end of input at 23..24 expected "property value", + ], + } + "### + ); + + insta::assert_debug_snapshot!( + parser.parse("implementation-status: implementing"), + @r###" + ParseResult { + output: Some( + ( + 0..35, + ImplementationStatus( + Unconditional( + Implementing, + ), + ), + ), + ), + errs: [], + } + "### + ); + + insta::assert_debug_snapshot!( + parser.parse("implementation-status: not-implementing"), + @r###" + ParseResult { + output: Some( + ( + 0..39, + ImplementationStatus( + Unconditional( + NotImplementing, + ), + ), + ), + ), + errs: [], + } + "### + ); + + insta::assert_debug_snapshot!( + parser.parse("implementation-status: backlog"), + @r###" + ParseResult { + output: Some( + ( + 0..30, + ImplementationStatus( + Unconditional( + Backlog, + ), + ), + ), + ), + errs: [], + } + "### + ); + + insta::assert_debug_snapshot!( + parser.parse("implementation-status: derp"), + @r###" + ParseResult { + output: None, + errs: [ + found end of input at 23..24 expected "property value", + ], + } + "### + ); + let parser = parser.padded(); insta::assert_debug_snapshot!( @@ -349,6 +451,7 @@ pub enum FileProp { Prefs(PropertyValue>, Vec<(String, String)>>), Tags(PropertyValue>, Vec>), Disabled(PropertyValue>, String>), + ImplementationStatus(PropertyValue>, ImplementationStatus>), } fn format_file_properties(props: &FileProps) -> impl Display + '_ { @@ -414,11 +517,21 @@ fn format_file_properties(props: &FileProps) -> impl Display + '_ { } lazy_format!(|f| { let FileProps { + implementation_status, is_disabled, prefs, tags, } = props; + if let Some(implementation_status) = implementation_status { + write_prop_val( + "implementation-status", + implementation_status, + Display::fmt, + f, + )?; + } + if let Some(prefs) = prefs { write_prop_val( "prefs", @@ -451,6 +564,34 @@ fn format_file_properties(props: &FileProps) -> impl Display + '_ { }) } +#[derive(Clone, Copy, Debug, Default)] +pub enum ImplementationStatus { + /// Indicates that functionality governing test(s) is implemented or currently being + /// implemented, and generally expected to conform to tests. + #[default] + Implementing, + /// Indicates that functionality governing test(s) is not yet implemented, but is intended to + /// be eventually. + Backlog, + /// Indicates that functionality governing test(s) is not implemented, with no plans for + /// eventual implementation. + NotImplementing, +} + +impl Display for ImplementationStatus { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + Self::Implementing => "implementing", + Self::Backlog => "backlog", + Self::NotImplementing => "not-implementing", + } + ) + } +} + #[derive(Debug, Default)] pub struct Tests(BTreeMap); @@ -1109,6 +1250,7 @@ r#" is_disabled: None, prefs: None, tags: None, + implementation_status: None, }, tests: { "asdf": Test { @@ -1141,6 +1283,7 @@ r#" is_disabled: None, prefs: None, tags: None, + implementation_status: None, }, tests: { "asdf": Test { @@ -1181,6 +1324,7 @@ r#" is_disabled: None, prefs: None, tags: None, + implementation_status: None, }, tests: { "asdf": Test {