Skip to content

Commit

Permalink
test(naga): cover diagnostic(…); parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Nov 5, 2024
1 parent 1add61c commit 0c5f071
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
13 changes: 13 additions & 0 deletions naga/src/diagnostic_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use serde::Serialize;
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(test, derive(strum::EnumIter))]
pub enum Severity {
Off,
Info,
Expand All @@ -27,6 +28,17 @@ pub enum Severity {
}

impl Severity {
/// Maps this [`Severity`] into the sentinel word associated with it in WGSL.
#[cfg(test)]
pub const fn to_ident(self) -> &'static str {
match self {
Self::Error => Self::ERROR,
Self::Warning => Self::WARNING,
Self::Info => Self::INFO,
Self::Off => Self::OFF,
}
}

/// Checks whether this severity is [`Self::Error`].
///
/// Naga does not yet support diagnostic items at lesser severities than
Expand Down Expand Up @@ -58,6 +70,7 @@ impl Severity {
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(test, derive(strum::EnumIter))]
pub enum FilterableTriggeringRule {
DerivativeUniformity,
}
Expand Down
71 changes: 71 additions & 0 deletions naga/src/front/wgsl/diagnostic_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,74 @@ impl FilterableTriggeringRule {
}
}
}

#[cfg(test)]
mod test {
use crate::diagnostic_filter::{FilterableTriggeringRule, Severity};
use crate::front::wgsl::assert_parse_err;

use itertools::Itertools as _;
use strum::IntoEnumIterator as _;

#[test]
fn basic() {}

#[test]
fn malformed() {
assert_parse_err("directive;", snapshot);
assert_parse_err("directive(off, asdf;", snapshot);
assert_parse_err("directive();", snapshot);
}

#[test]
fn severities() {}

#[test]
fn invalid_severity() {}

#[test]
fn triggering_rules() {}

#[test]
fn invalid_triggering_rule() {
#[derive(Debug, Clone)]
enum Rule {
Valid(FilterableTriggeringRule),
Invalid,
}

#[derive(Debug, Clone)]
enum Sev {
Valid(Severity),
Invalid,
}

let cases = {
let invalid_sev_cases = FilterableTriggeringRule::iter()
.map(Rule::Valid)
.cartesian_product([Sev::Invalid]);
let invalid_rule_cases = [Rule::Invalid]
.into_iter()
.cartesian_product(Severity::iter().map(Sev::Valid));
invalid_sev_cases.chain(invalid_rule_cases)
};

for (rule, severity) in cases {
let rule = match rule {
Rule::Valid(rule) => rule.to_wgsl_ident(),
Rule::Invalid => "totes_invalid_rule",
};
let severity = match severity {
Sev::Valid(severity) => severity.to_ident(),
Sev::Invalid => "totes_invalid_severity",
};
let shader = format!("diagnostic({severity},{rule});");
let expected_msg = format!(
"\
"
);

assert_parse_err(&shader, &expected_msg);
}
}
}

0 comments on commit 0c5f071

Please sign in to comment.