15826
|
1 |
use hedgewars_network_protocol::{
|
|
2 |
parser::message,
|
|
3 |
types::GameCfg,
|
|
4 |
{messages::HwProtocolMessage::*, parser::HwProtocolError},
|
|
5 |
};
|
|
6 |
|
|
7 |
#[test]
|
|
8 |
fn parse_test() {
|
|
9 |
assert_eq!(message(b"PING\n\n"), Ok((&b""[..], Ping)));
|
|
10 |
assert_eq!(message(b"START_GAME\n\n"), Ok((&b""[..], StartGame)));
|
|
11 |
assert_eq!(
|
|
12 |
message(b"NICK\nit's me\n\n"),
|
|
13 |
Ok((&b""[..], Nick("it's me".to_string())))
|
|
14 |
);
|
|
15 |
assert_eq!(message(b"PROTO\n51\n\n"), Ok((&b""[..], Proto(51))));
|
|
16 |
assert_eq!(
|
|
17 |
message(b"QUIT\nbye-bye\n\n"),
|
|
18 |
Ok((&b""[..], Quit(Some("bye-bye".to_string()))))
|
|
19 |
);
|
|
20 |
assert_eq!(message(b"QUIT\n\n"), Ok((&b""[..], Quit(None))));
|
|
21 |
assert_eq!(
|
|
22 |
message(b"CMD\nwatch 49471\n\n"),
|
|
23 |
Ok((&b""[..], Watch(49471)))
|
|
24 |
);
|
|
25 |
assert_eq!(
|
|
26 |
message(b"BAN\nme\nbad\n77\n\n"),
|
|
27 |
Ok((&b""[..], Ban("me".to_string(), "bad".to_string(), 77)))
|
|
28 |
);
|
|
29 |
|
|
30 |
assert_eq!(message(b"CMD\nPART\n\n"), Ok((&b""[..], Part(None))));
|
|
31 |
assert_eq!(
|
|
32 |
message(b"CMD\nPART _msg_\n\n"),
|
|
33 |
Ok((&b""[..], Part(Some("_msg_".to_string()))))
|
|
34 |
);
|
|
35 |
|
|
36 |
assert_eq!(message(b"CMD\nRND\n\n"), Ok((&b""[..], Rnd(vec![]))));
|
|
37 |
assert_eq!(
|
|
38 |
message(b"CMD\nRND A B\n\n"),
|
|
39 |
Ok((&b""[..], Rnd(vec![String::from("A"), String::from("B")])))
|
|
40 |
);
|
|
41 |
|
|
42 |
assert_eq!(
|
|
43 |
message(b"CFG\nSCHEME\na\nA\n\n"),
|
|
44 |
Ok((
|
|
45 |
&b""[..],
|
|
46 |
Cfg(GameCfg::Scheme("a".to_string(), vec!["A".to_string()]))
|
|
47 |
))
|
|
48 |
);
|
|
49 |
|
|
50 |
assert_eq!(
|
|
51 |
message(b"QUIT\n1\n2\n\n"),
|
|
52 |
Err(nom::Err::Error(HwProtocolError::new()))
|
|
53 |
);
|
|
54 |
}
|