minecraft_command_types/command/
test.rs

1use crate::resource_location::ResourceLocation;
2use minecraft_command_types_derive::HasMacro;
3use std::fmt::{Display, Formatter};
4
5#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
6pub enum RunfailedTestCommand {
7    NumberOfTimes(Option<i32>, Option<bool>, Option<i32>, Option<i32>),
8    OnlyRequiredTest(Option<bool>, Option<i32>),
9}
10
11impl Display for RunfailedTestCommand {
12    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13        match self {
14            RunfailedTestCommand::NumberOfTimes(
15                number_of_times,
16                until_failed,
17                rotation_steps,
18                tests_per_row,
19            ) => {
20                if let Some(number_of_times) = number_of_times {
21                    write!(f, " {}", number_of_times)?;
22
23                    if let Some(until_failed) = until_failed {
24                        write!(f, " {}", until_failed)?;
25
26                        if let Some(rotation_steps) = rotation_steps {
27                            write!(f, " {}", rotation_steps)?;
28
29                            if let Some(tests_per_row) = tests_per_row {
30                                write!(f, " {}", tests_per_row)?;
31                            }
32                        }
33                    }
34                }
35
36                Ok(())
37            }
38            RunfailedTestCommand::OnlyRequiredTest(only_required_tests, number_of_times) => {
39                if let Some(only_required_tests) = only_required_tests {
40                    write!(f, " {}", only_required_tests)?;
41
42                    if let Some(number_of_times) = number_of_times {
43                        write!(f, " {}", number_of_times)?;
44                    }
45                }
46
47                Ok(())
48            }
49        }
50    }
51}
52
53#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
54pub enum TestCommand {
55    ClearAll(Option<i32>),
56    ClearThat,
57    ClearThese,
58    Create(ResourceLocation, Option<i32>, Option<(i32, i32)>),
59    Locate(ResourceLocation),
60    Pos(Option<String>),
61    ResetClosest,
62    ResetThat,
63    ResetThese,
64    Run(
65        ResourceLocation,
66        Option<i32>,
67        Option<bool>,
68        Option<i32>,
69        Option<i32>,
70    ),
71    RunClosest(Option<i32>, Option<bool>),
72    RunThat(Option<i32>, Option<bool>),
73    RunThese(Option<i32>, Option<bool>),
74    RunMultiple(ResourceLocation, Option<i32>),
75    RunFailed(RunfailedTestCommand),
76    Stop,
77    Verify(ResourceLocation),
78    Export(ResourceLocation),
79    ExportClosest,
80    ExportThat,
81    ExportThese,
82}
83
84impl Display for TestCommand {
85    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
86        match self {
87            TestCommand::ClearAll(radius) => {
88                f.write_str("clearall")?;
89
90                if let Some(radius) = radius {
91                    write!(f, " {}", radius)?;
92                }
93
94                Ok(())
95            }
96            TestCommand::ClearThat => f.write_str("clearthat"),
97            TestCommand::ClearThese => f.write_str("clearthese"),
98            TestCommand::Create(location, width, height_depth) => {
99                write!(f, "create {}", location)?;
100
101                if let Some(width) = width {
102                    write!(f, " {}", width)?;
103
104                    if let Some((height, depth)) = height_depth {
105                        write!(f, " {} {}", height, depth)?;
106                    }
107                }
108
109                Ok(())
110            }
111            TestCommand::Locate(location) => write!(f, "locate {}", location),
112            TestCommand::Pos(variable) => {
113                f.write_str("pos")?;
114
115                if let Some(variable) = variable {
116                    write!(f, " {}", variable)?;
117                }
118
119                Ok(())
120            }
121            TestCommand::ResetClosest => f.write_str("resetclosest"),
122            TestCommand::ResetThat => f.write_str("resetthat"),
123            TestCommand::ResetThese => f.write_str("resetthese"),
124            TestCommand::Run(
125                location,
126                number_of_times,
127                until_failed,
128                rotation_step,
129                tests_per_row,
130            ) => {
131                write!(f, "run {}", location)?;
132
133                if let Some(number_of_times) = number_of_times {
134                    write!(f, " {}", number_of_times)?;
135
136                    if let Some(until_failed) = until_failed {
137                        write!(f, " {}", until_failed)?;
138
139                        if let Some(rotation_steps) = rotation_step {
140                            write!(f, " {}", rotation_steps)?;
141
142                            if let Some(tests_per_row) = tests_per_row {
143                                write!(f, " {}", tests_per_row)?;
144                            }
145                        }
146                    }
147                }
148
149                Ok(())
150            }
151            TestCommand::RunClosest(number_of_times, until_failed) => {
152                f.write_str("runclosest")?;
153
154                if let Some(number_of_times) = number_of_times {
155                    write!(f, " {}", number_of_times)?;
156
157                    if let Some(until_failed) = until_failed {
158                        write!(f, " {}", until_failed)?;
159                    }
160                }
161
162                Ok(())
163            }
164            TestCommand::RunThat(number_of_times, until_failed) => {
165                f.write_str("runthat")?;
166
167                if let Some(number_of_times) = number_of_times {
168                    write!(f, " {}", number_of_times)?;
169
170                    if let Some(until_failed) = until_failed {
171                        write!(f, " {}", until_failed)?;
172                    }
173                }
174
175                Ok(())
176            }
177            TestCommand::RunThese(number_of_times, until_failed) => {
178                f.write_str("runthese")?;
179
180                if let Some(number_of_times) = number_of_times {
181                    write!(f, " {}", number_of_times)?;
182
183                    if let Some(until_failed) = until_failed {
184                        write!(f, " {}", until_failed)?;
185                    }
186                }
187
188                Ok(())
189            }
190            TestCommand::RunMultiple(location, amount) => {
191                write!(f, "runmultiple {}", location)?;
192
193                if let Some(amount) = amount {
194                    write!(f, " {}", amount)?;
195                }
196
197                Ok(())
198            }
199            TestCommand::RunFailed(command) => write!(f, "runfailed {}", command),
200            TestCommand::Stop => f.write_str("stop"),
201            TestCommand::Verify(location) => write!(f, "verify {}", location),
202            TestCommand::Export(location) => write!(f, "export {}", location),
203            TestCommand::ExportClosest => f.write_str("exportclosest"),
204            TestCommand::ExportThat => f.write_str("exportthat"),
205            TestCommand::ExportThese => f.write_str("exportthese"),
206        }
207    }
208}