gameServer2/src/protocol/test.rs
changeset 13666 09f4a30e50cc
parent 13528 c8b626b0a3ad
child 13771 4664da990556
equal deleted inserted replaced
13665:5664650befcd 13666:09f4a30e50cc
     2     test_runner::{TestRunner, Reason},
     2     test_runner::{TestRunner, Reason},
     3     arbitrary::{any, any_with, Arbitrary, StrategyFor},
     3     arbitrary::{any, any_with, Arbitrary, StrategyFor},
     4     strategy::{Strategy, BoxedStrategy, Just, Map},
     4     strategy::{Strategy, BoxedStrategy, Just, Map},
     5 };
     5 };
     6 
     6 
     7 use server::coretypes::{GameCfg, TeamInfo, HedgehogInfo};
     7 use crate::server::coretypes::{GameCfg, TeamInfo, HedgehogInfo};
     8 
     8 
     9 use super::messages::{
     9 use super::messages::{
    10     HWProtocolMessage, HWProtocolMessage::*
    10     HWProtocolMessage, HWProtocolMessage::*
    11 };
    11 };
    12 
    12 
    51 struct Ascii(String);
    51 struct Ascii(String);
    52 
    52 
    53 impl Arbitrary for Ascii {
    53 impl Arbitrary for Ascii {
    54     type Parameters = <String as Arbitrary>::Parameters;
    54     type Parameters = <String as Arbitrary>::Parameters;
    55 
    55 
    56     fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
    56     fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
    57         "[a-zA-Z0-9]+".prop_map(Ascii).boxed()
    57         "[a-zA-Z0-9]+".prop_map(Ascii).boxed()
    58     }
    58     }
    59 
    59 
    60     type Strategy = BoxedStrategy<Ascii>;
    60     type Strategy = BoxedStrategy<Ascii>;
    61 }
    61 }
    62 
    62 
    63 impl Arbitrary for GameCfg {
    63 impl Arbitrary for GameCfg {
    64     type Parameters = ();
    64     type Parameters = ();
    65 
    65 
    66     fn arbitrary_with(args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
    66     fn arbitrary_with(_args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
    67         use server::coretypes::GameCfg::*;
    67         use crate::server::coretypes::GameCfg::*;
    68         (0..10).no_shrink().prop_flat_map(|i| {
    68         (0..10).no_shrink().prop_flat_map(|i| {
    69             proto_msg_match!(i, def = FeatureSize(0),
    69             proto_msg_match!(i, def = FeatureSize(0),
    70             0 => FeatureSize(u32),
    70             0 => FeatureSize(u32),
    71             1 => MapType(Ascii),
    71             1 => MapType(Ascii),
    72             2 => MapGenerator(u32),
    72             2 => MapGenerator(u32),
    85 }
    85 }
    86 
    86 
    87 impl Arbitrary for TeamInfo {
    87 impl Arbitrary for TeamInfo {
    88     type Parameters = ();
    88     type Parameters = ();
    89 
    89 
    90     fn arbitrary_with(args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
    90     fn arbitrary_with(_args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
    91         ("[a-z]+", 0u8..127u8, "[a-z]+", "[a-z]+", "[a-z]+", "[a-z]+",  0u8..127u8)
    91         ("[a-z]+", 0u8..127u8, "[a-z]+", "[a-z]+", "[a-z]+", "[a-z]+",  0u8..127u8)
    92             .prop_map(|(name, color, grave, fort, voice_pack, flag, difficulty)| {
    92             .prop_map(|(name, color, grave, fort, voice_pack, flag, difficulty)| {
    93                 fn hog(n: u8) -> HedgehogInfo {
    93                 fn hog(n: u8) -> HedgehogInfo {
    94                     HedgehogInfo { name: format!("hog{}", n), hat: format!("hat{}", n)}
    94                     HedgehogInfo { name: format!("hog{}", n), hat: format!("hat{}", n)}
    95                 }
    95                 }