rust/hedgewars-server/src/protocol/test.rs
author Wuzzy <Wuzzy2@mail.ru>
Thu, 11 Jul 2019 16:24:09 +0200
changeset 15231 c10e9261ab9c
parent 15124 824472aa4d97
permissions -rw-r--r--
Make lowest line of Splash image frames transparent to work around scaling issues The Splash image is scaled. Sometimes, the lowest line is repeated on the top, which caused some weird lines to appear above big splashes (e.g. piano). This has been done fully automated with a script. Only the alpha channel was changed. The color information is preserved.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
     1
use proptest::{
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
     2
    arbitrary::{any, any_with, Arbitrary, StrategyFor},
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
     3
    strategy::{BoxedStrategy, Just, Map, Strategy},
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
     4
    test_runner::{Reason, TestRunner},
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
     5
};
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
     6
15112
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
     7
use crate::core::types::{GameCfg, HedgehogInfo, ServerVar, ServerVar::*, TeamInfo, VoteType};
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
     8
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
     9
use super::messages::{HwProtocolMessage, HwProtocolMessage::*};
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    10
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    11
// Due to inability to define From between Options
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    12
trait Into2<T>: Sized {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    13
    fn into2(self) -> T;
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    14
}
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    15
impl<T> Into2<T> for T {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    16
    fn into2(self) -> T {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    17
        self
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    18
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    19
}
13433
fb104e150878 Implement to_raw_protocol for Rnd and enable tests. Add cargo/rls build artifacts to .gitignore
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13432
diff changeset
    20
impl Into2<Vec<String>> for Vec<Ascii> {
fb104e150878 Implement to_raw_protocol for Rnd and enable tests. Add cargo/rls build artifacts to .gitignore
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13432
diff changeset
    21
    fn into2(self) -> Vec<String> {
fb104e150878 Implement to_raw_protocol for Rnd and enable tests. Add cargo/rls build artifacts to .gitignore
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13432
diff changeset
    22
        self.into_iter().map(|x| x.0).collect()
fb104e150878 Implement to_raw_protocol for Rnd and enable tests. Add cargo/rls build artifacts to .gitignore
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13432
diff changeset
    23
    }
fb104e150878 Implement to_raw_protocol for Rnd and enable tests. Add cargo/rls build artifacts to .gitignore
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13432
diff changeset
    24
}
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    25
impl Into2<String> for Ascii {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    26
    fn into2(self) -> String {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    27
        self.0
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    28
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    29
}
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    30
impl Into2<Option<String>> for Option<Ascii> {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    31
    fn into2(self) -> Option<String> {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    32
        self.map(|x| x.0)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    33
    }
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    34
}
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    35
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    36
macro_rules! proto_msg_case {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    37
    ($val: ident()) => {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    38
        Just($val)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    39
    };
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    40
    ($val: ident($arg: ty)) => {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    41
        any::<$arg>().prop_map(|v| $val(v.into2()))
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    42
    };
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    43
    ($val: ident($arg1: ty, $arg2: ty)) => {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    44
        any::<($arg1, $arg2)>().prop_map(|v| $val(v.0.into2(), v.1.into2()))
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    45
    };
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    46
    ($val: ident($arg1: ty, $arg2: ty, $arg3: ty)) => {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    47
        any::<($arg1, $arg2, $arg3)>().prop_map(|v| $val(v.0.into2(), v.1.into2(), v.2.into2()))
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    48
    };
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    49
}
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    50
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    51
macro_rules! proto_msg_match {
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    52
    ($var: expr, def = $default: expr, $($num: expr => $constr: ident $res: tt),*) => (
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    53
        match $var {
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    54
            $($num => (proto_msg_case!($constr $res)).boxed()),*,
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    55
            _ => Just($default).boxed()
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    56
        }
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    57
    )
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    58
}
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    59
13432
ee3fa3b8809d Fix cmd parsing & update tests
alfadur
parents: 13421
diff changeset
    60
/// Wrapper type for generating non-empty strings
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    61
#[derive(Debug)]
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    62
struct Ascii(String);
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    63
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    64
impl Arbitrary for Ascii {
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    65
    type Parameters = <String as Arbitrary>::Parameters;
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    66
13666
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13528
diff changeset
    67
    fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
13482
7f3289a239dd Optimize test string generation
alfadur
parents: 13478
diff changeset
    68
        "[a-zA-Z0-9]+".prop_map(Ascii).boxed()
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    69
    }
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    70
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    71
    type Strategy = BoxedStrategy<Ascii>;
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    72
}
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
    73
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    74
impl Arbitrary for GameCfg {
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    75
    type Parameters = ();
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    76
13666
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13528
diff changeset
    77
    fn arbitrary_with(_args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
15074
c5a6e8566425 shuffle server files
alfadur
parents: 14795
diff changeset
    78
        use crate::core::types::GameCfg::*;
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    79
        (0..10)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    80
            .no_shrink()
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    81
            .prop_flat_map(|i| {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    82
                proto_msg_match!(i, def = FeatureSize(0),
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    83
            0 => FeatureSize(u32),
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    84
            1 => MapType(Ascii),
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    85
            2 => MapGenerator(u32),
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    86
            3 => MazeSize(u32),
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    87
            4 => Seed(Ascii),
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    88
            5 => Template(u32),
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    89
            6 => Ammo(Ascii, Option<Ascii>),
13801
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13798
diff changeset
    90
            7 => Scheme(Ascii, Vec<Ascii>),
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    91
            8 => Script(Ascii),
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    92
            9 => Theme(Ascii),
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    93
            10 => DrawnMap(Ascii))
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    94
            })
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    95
            .boxed()
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    96
    }
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    97
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    98
    type Strategy = BoxedStrategy<GameCfg>;
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
    99
}
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   100
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   101
impl Arbitrary for TeamInfo {
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   102
    type Parameters = ();
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   103
13666
09f4a30e50cc Rust 2018 conversion
alfadur
parents: 13528
diff changeset
   104
    fn arbitrary_with(_args: <Self as Arbitrary>::Parameters) -> <Self as Arbitrary>::Strategy {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   105
        (
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   106
            "[a-z]+",
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   107
            0u8..127u8,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   108
            "[a-z]+",
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   109
            "[a-z]+",
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   110
            "[a-z]+",
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   111
            "[a-z]+",
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   112
            0u8..127u8,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   113
        )
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   114
            .prop_map(|(name, color, grave, fort, voice_pack, flag, difficulty)| {
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   115
                fn hog(n: u8) -> HedgehogInfo {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   116
                    HedgehogInfo {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   117
                        name: format!("hog{}", n),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   118
                        hat: format!("hat{}", n),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   119
                    }
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   120
                }
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   121
                let hedgehogs = [
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   122
                    hog(1),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   123
                    hog(2),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   124
                    hog(3),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   125
                    hog(4),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   126
                    hog(5),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   127
                    hog(6),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   128
                    hog(7),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   129
                    hog(8),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   130
                ];
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   131
                TeamInfo {
14795
add191d825f4 add parser error handling
alfadur
parents: 14783
diff changeset
   132
                    owner: String::new(),
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   133
                    name,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   134
                    color,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   135
                    grave,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   136
                    fort,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   137
                    voice_pack,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   138
                    flag,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   139
                    difficulty,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   140
                    hedgehogs,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   141
                    hedgehogs_number: 0,
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   142
                }
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   143
            })
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   144
            .boxed()
13439
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   145
    }
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   146
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   147
    type Strategy = BoxedStrategy<TeamInfo>;
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   148
}
c4f917c6be51 add missing message tests
alfadur
parents: 13437
diff changeset
   149
14783
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   150
impl Arbitrary for ServerVar {
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   151
    type Parameters = ();
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   152
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   153
    fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
14795
add191d825f4 add parser error handling
alfadur
parents: 14783
diff changeset
   154
        (0..=2)
14783
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   155
            .no_shrink()
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   156
            .prop_flat_map(|i| {
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   157
                proto_msg_match!(i, def = ServerVar::LatestProto(0),
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   158
                    0 => MOTDNew(Ascii),
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   159
                    1 => MOTDOld(Ascii),
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   160
                    2 => LatestProto(u16)
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   161
                )
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   162
            })
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   163
            .boxed()
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   164
    }
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   165
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   166
    type Strategy = BoxedStrategy<ServerVar>;
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   167
}
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   168
15112
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   169
impl Arbitrary for VoteType {
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   170
    type Parameters = ();
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   171
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   172
    fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   173
        use VoteType::*;
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   174
        (0..=4)
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   175
            .no_shrink()
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   176
            .prop_flat_map(|i| {
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   177
                proto_msg_match!(i, def = VoteType::Pause,
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   178
                    0 => Kick(Ascii),
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   179
                    1 => Map(Option<Ascii>),
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   180
                    2 => Pause(),
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   181
                    3 => NewSeed(),
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   182
                    4 => HedgehogsPerTeam(u8)
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   183
                )
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   184
            })
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   185
            .boxed()
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   186
    }
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   187
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   188
    type Strategy = BoxedStrategy<VoteType>;
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   189
}
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   190
15075
e935b1ad23f3 normalize type names
alfadur
parents: 15074
diff changeset
   191
pub fn gen_proto_msg() -> BoxedStrategy<HwProtocolMessage> where {
14795
add191d825f4 add parser error handling
alfadur
parents: 14783
diff changeset
   192
    let res = (0..=55).no_shrink().prop_flat_map(|i| {
add191d825f4 add parser error handling
alfadur
parents: 14783
diff changeset
   193
        proto_msg_match!(i, def = Ping,
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   194
            0 => Ping(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   195
            1 => Pong(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   196
            2 => Quit(Option<Ascii>),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   197
            4 => Global(Ascii),
14795
add191d825f4 add parser error handling
alfadur
parents: 14783
diff changeset
   198
            5 => Watch(u32),
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   199
            6 => ToggleServerRegisteredOnly(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   200
            7 => SuperPower(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   201
            8 => Info(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   202
            9 => Nick(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   203
            10 => Proto(u16),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   204
            11 => Password(Ascii, Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   205
            12 => Checker(u16, Ascii, Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   206
            13 => List(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   207
            14 => Chat(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   208
            15 => CreateRoom(Ascii, Option<Ascii>),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   209
            16 => JoinRoom(Ascii, Option<Ascii>),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   210
            17 => Follow(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   211
            18 => Rnd(Vec<Ascii>),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   212
            19 => Kick(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   213
            20 => Ban(Ascii, Ascii, u32),
15124
824472aa4d97 use tuple parsers
alfadur
parents: 15112
diff changeset
   214
            21 => BanIp(Ascii, Ascii, u32),
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   215
            22 => BanNick(Ascii, Ascii, u32),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   216
            23 => BanList(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   217
            24 => Unban(Ascii),
14783
b3adc030104b implement server vars
alfadur
parents: 14457
diff changeset
   218
            25 => SetServerVar(ServerVar),
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   219
            26 => GetServerVar(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   220
            27 => RestartServer(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   221
            28 => Stats(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   222
            29 => Part(Option<Ascii>),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   223
            30 => Cfg(GameCfg),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   224
            31 => AddTeam(Box<TeamInfo>),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   225
            32 => RemoveTeam(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   226
            33 => SetHedgehogsNumber(Ascii, u8),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   227
            34 => SetTeamColor(Ascii, u8),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   228
            35 => ToggleReady(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   229
            36 => StartGame(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   230
            37 => EngineMessage(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   231
            38 => RoundFinished(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   232
            39 => ToggleRestrictJoin(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   233
            40 => ToggleRestrictTeams(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   234
            41 => ToggleRegisteredOnly(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   235
            42 => RoomName(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   236
            43 => Delegate(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   237
            44 => TeamChat(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   238
            45 => MaxTeams(u8),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   239
            46 => Fix(),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   240
            47 => Unfix(),
15111
1e45db229f9f make greeting argument optional
alfadur
parents: 15075
diff changeset
   241
            48 => Greeting(Option<Ascii>),
15112
6a1ba3540fa0 fix callvote parsing
alfadur
parents: 15111
diff changeset
   242
            49 => CallVote(Option<VoteType>),
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   243
            50 => Vote(bool),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   244
            51 => ForceVote(bool),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   245
            52 => Save(Ascii, Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   246
            53 => Delete(Ascii),
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   247
            54 => SaveRoom(Ascii),
14795
add191d825f4 add parser error handling
alfadur
parents: 14783
diff changeset
   248
            55 => LoadRoom(Ascii)
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   249
        )
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
   250
    });
13419
81e0ed105f5d implementation of team related messages
alfadur
parents:
diff changeset
   251
    res.boxed()
13421
d1368c776a4f Enable all lints from the rust-2018-idioms suite.
marmistrz
parents: 13419
diff changeset
   252
}