From 0c5f071ba296e0a29efb175ceb7ba802e348b7d4 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 23 Oct 2024 17:04:21 -0400 Subject: [PATCH] =?UTF-8?q?test(naga):=20cover=20`diagnostic(=E2=80=A6);`?= =?UTF-8?q?=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- naga/src/diagnostic_filter.rs | 13 +++++ naga/src/front/wgsl/diagnostic_filter.rs | 71 ++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/naga/src/diagnostic_filter.rs b/naga/src/diagnostic_filter.rs index ca2c96fa5c..480b71e498 100644 --- a/naga/src/diagnostic_filter.rs +++ b/naga/src/diagnostic_filter.rs @@ -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, @@ -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 @@ -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, } diff --git a/naga/src/front/wgsl/diagnostic_filter.rs b/naga/src/front/wgsl/diagnostic_filter.rs index 923bac7a3e..c3b6d0b034 100644 --- a/naga/src/front/wgsl/diagnostic_filter.rs +++ b/naga/src/front/wgsl/diagnostic_filter.rs @@ -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); + } + } +}