2 arbitrary::{any, any_with, Arbitrary, StrategyFor}, |
2 arbitrary::{any, any_with, Arbitrary, StrategyFor}, |
3 strategy::{BoxedStrategy, Just, Map, Strategy}, |
3 strategy::{BoxedStrategy, Just, Map, Strategy}, |
4 test_runner::{Reason, TestRunner}, |
4 test_runner::{Reason, TestRunner}, |
5 }; |
5 }; |
6 |
6 |
7 use crate::server::coretypes::{GameCfg, HedgehogInfo, TeamInfo}; |
7 use crate::server::coretypes::{GameCfg, HedgehogInfo, ServerVar, ServerVar::*, TeamInfo}; |
8 |
8 |
9 use super::messages::{HWProtocolMessage, HWProtocolMessage::*}; |
9 use super::messages::{HWProtocolMessage, HWProtocolMessage::*}; |
10 |
10 |
11 // Due to inability to define From between Options |
11 // Due to inability to define From between Options |
12 trait Into2<T>: Sized { |
12 trait Into2<T>: Sized { |
144 } |
144 } |
145 |
145 |
146 type Strategy = BoxedStrategy<TeamInfo>; |
146 type Strategy = BoxedStrategy<TeamInfo>; |
147 } |
147 } |
148 |
148 |
|
149 impl Arbitrary for ServerVar { |
|
150 type Parameters = (); |
|
151 |
|
152 fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { |
|
153 (0..2) |
|
154 .no_shrink() |
|
155 .prop_flat_map(|i| { |
|
156 proto_msg_match!(i, def = ServerVar::LatestProto(0), |
|
157 0 => MOTDNew(Ascii), |
|
158 1 => MOTDOld(Ascii), |
|
159 2 => LatestProto(u16) |
|
160 ) |
|
161 }) |
|
162 .boxed() |
|
163 } |
|
164 |
|
165 type Strategy = BoxedStrategy<ServerVar>; |
|
166 } |
|
167 |
149 pub fn gen_proto_msg() -> BoxedStrategy<HWProtocolMessage> where { |
168 pub fn gen_proto_msg() -> BoxedStrategy<HWProtocolMessage> where { |
150 let res = (0..58).no_shrink().prop_flat_map(|i| { |
169 let res = (0..58).no_shrink().prop_flat_map(|i| { |
151 proto_msg_match!(i, def = Malformed, |
170 proto_msg_match!(i, def = Malformed, |
152 0 => Ping(), |
171 0 => Ping(), |
153 1 => Pong(), |
172 1 => Pong(), |
172 20 => Ban(Ascii, Ascii, u32), |
191 20 => Ban(Ascii, Ascii, u32), |
173 21 => BanIP(Ascii, Ascii, u32), |
192 21 => BanIP(Ascii, Ascii, u32), |
174 22 => BanNick(Ascii, Ascii, u32), |
193 22 => BanNick(Ascii, Ascii, u32), |
175 23 => BanList(), |
194 23 => BanList(), |
176 24 => Unban(Ascii), |
195 24 => Unban(Ascii), |
177 //25 => SetServerVar(ServerVar), |
196 25 => SetServerVar(ServerVar), |
178 26 => GetServerVar(), |
197 26 => GetServerVar(), |
179 27 => RestartServer(), |
198 27 => RestartServer(), |
180 28 => Stats(), |
199 28 => Stats(), |
181 29 => Part(Option<Ascii>), |
200 29 => Part(Option<Ascii>), |
182 30 => Cfg(GameCfg), |
201 30 => Cfg(GameCfg), |