1use serde::Serialize;
2
3#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum CaseRequirement {
7 #[default]
9 Functional,
10 Exact,
12}
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
16pub struct CaseMetadata {
17 id: &'static str,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 source_test: Option<&'static str>,
20 spec_references: &'static [&'static str],
21 #[serde(skip)]
22 requirement: CaseRequirement,
23}
24
25impl CaseMetadata {
26 pub(crate) const fn new(
27 id: &'static str,
28 source_test: &'static str,
29 spec_references: &'static [&'static str],
30 ) -> Self {
31 Self {
32 id,
33 source_test: Some(source_test),
34 spec_references,
35 requirement: CaseRequirement::Functional,
36 }
37 }
38
39 pub const fn id(self) -> &'static str {
41 self.id
42 }
43
44 pub const fn source_test(self) -> Option<&'static str> {
47 self.source_test
48 }
49
50 pub(crate) const fn closure(
51 id: &'static str,
52 spec_references: &'static [&'static str],
53 ) -> Self {
54 Self {
55 id,
56 source_test: None,
57 spec_references,
58 requirement: CaseRequirement::Functional,
59 }
60 }
61
62 pub(crate) const fn exact(id: &'static str, spec_references: &'static [&'static str]) -> Self {
63 Self {
64 id,
65 source_test: None,
66 spec_references,
67 requirement: CaseRequirement::Exact,
68 }
69 }
70
71 pub const fn spec_references(self) -> &'static [&'static str] {
73 self.spec_references
74 }
75
76 pub const fn requirement(self) -> CaseRequirement {
78 self.requirement
79 }
80}
81
82pub(crate) type CaseFn = fn();
83
84#[derive(Clone, Copy)]
85pub(crate) struct CaseDefinition {
86 pub metadata: CaseMetadata,
87 pub run: Option<CaseFn>,
88 pub skip_reason: Option<&'static str>,
89}
90
91impl CaseDefinition {
92 pub const fn new(metadata: CaseMetadata, run: CaseFn) -> Self {
93 Self {
94 metadata,
95 run: Some(run),
96 skip_reason: None,
97 }
98 }
99
100 pub const fn skipped(metadata: CaseMetadata, reason: &'static str) -> Self {
101 Self {
102 metadata,
103 run: None,
104 skip_reason: Some(reason),
105 }
106 }
107}