Skip to content

Commit

Permalink
feat: parse implementation-status property
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Apr 3, 2024
1 parent a82d347 commit 86171b4
Showing 1 changed file with 146 additions and 2 deletions.
148 changes: 146 additions & 2 deletions moz-webgpu-cts/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct FileProps {
#[allow(clippy::type_complexity)]
pub prefs: Option<PropertyValue<Expr<Value<'static>>, Vec<(String, String)>>>,
pub tags: Option<PropertyValue<Expr<Value<'static>>, Vec<String>>>,
pub implementation_status: Option<PropertyValue<Expr<Value<'static>>, ImplementationStatus>>,
}

impl<'a> Properties<'a> for FileProps {
Expand Down Expand Up @@ -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()
Expand All @@ -138,14 +139,29 @@ 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()
}

fn add_property(&mut self, prop: Self::ParsedProperty, emitter: &mut Emitter<Rich<'a, char>>) {
let (span, prop) = prop;
let Self {
implementation_status,
is_disabled,
prefs,
tags,
Expand All @@ -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) => {
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -349,6 +451,7 @@ pub enum FileProp {
Prefs(PropertyValue<Expr<Value<'static>>, Vec<(String, String)>>),
Tags(PropertyValue<Expr<Value<'static>>, Vec<String>>),
Disabled(PropertyValue<Expr<Value<'static>>, String>),
ImplementationStatus(PropertyValue<Expr<Value<'static>>, ImplementationStatus>),
}

fn format_file_properties(props: &FileProps) -> impl Display + '_ {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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<SectionHeader, Test>);

Expand Down Expand Up @@ -1109,6 +1250,7 @@ r#"
is_disabled: None,
prefs: None,
tags: None,
implementation_status: None,
},
tests: {
"asdf": Test {
Expand Down Expand Up @@ -1141,6 +1283,7 @@ r#"
is_disabled: None,
prefs: None,
tags: None,
implementation_status: None,
},
tests: {
"asdf": Test {
Expand Down Expand Up @@ -1181,6 +1324,7 @@ r#"
is_disabled: None,
prefs: None,
tags: None,
implementation_status: None,
},
tests: {
"asdf": Test {
Expand Down

0 comments on commit 86171b4

Please sign in to comment.