gameServer2/src/protocol/test.rs
changeset 13482 7f3289a239dd
parent 13478 d79795acaa73
child 13520 1ee192f13456
equal deleted inserted replaced
13481:8697b235f236 13482:7f3289a239dd
     1 use proptest::{
     1 use proptest::{
     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, Filter, ValueTree},
     4     strategy::{Strategy, BoxedStrategy, Just, Map},
     5     string::RegexGeneratorValueTree,
       
     6 };
     5 };
     7 
     6 
     8 use server::coretypes::{GameCfg, TeamInfo, HedgehogInfo};
     7 use server::coretypes::{GameCfg, TeamInfo, HedgehogInfo};
     9 
     8 
    10 use super::messages::{
     9 use super::messages::{
    53 
    52 
    54 impl Arbitrary for Ascii {
    53 impl Arbitrary for Ascii {
    55     type Parameters = <String as Arbitrary>::Parameters;
    54     type Parameters = <String as Arbitrary>::Parameters;
    56 
    55 
    57     fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
    56     fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
    58         any_with::<String>(args)
    57         "[a-zA-Z0-9]+".prop_map(Ascii).boxed()
    59             .prop_filter("not ascii", |s| {
       
    60                 s.len() > 0 && s.is_ascii() &&
       
    61                     s.find(|c| {
       
    62                         ['\0', '\n', '\x20'].contains(&c)
       
    63                     }).is_none()})
       
    64             .prop_map(Ascii)
       
    65             .boxed()
       
    66     }
    58     }
    67 
    59 
    68     type Strategy = BoxedStrategy<Ascii>;
    60     type Strategy = BoxedStrategy<Ascii>;
    69 }
    61 }
    70 
    62