Skip to content

Commit

Permalink
WIP: test(naga): add cvg. for diagnostic directive parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Oct 25, 2024
1 parent 04bb94f commit 59ff6b1
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 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 @@ -43,6 +44,17 @@ 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 @@ -74,6 +86,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 Expand Up @@ -216,3 +229,75 @@ impl DiagnosticFilterNode {
triggering_rule.default_severity()
}
}

#[cfg(test)]
mod test {
use crate::front::wgsl::assert_parse_err;

use super::{DiagnosticTriggeringRule, Severity};

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(DiagnosticTriggeringRule),
Invalid,
}

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

let cases = {
let invalid_sev_cases = DiagnosticTriggeringRule::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_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 59ff6b1

Please sign in to comment.