author | unc0rr |
Sun, 16 Dec 2018 00:12:29 +0100 | |
changeset 14457 | 98ef2913ec73 |
parent 14415 | 06672690d71b |
child 14775 | 09d46ab83361 |
permissions | -rw-r--r-- |
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
1 |
/** The parsers for the chat and multiplayer protocol. The main parser is `message`. |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
2 |
* # Protocol |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
3 |
* All messages consist of `\n`-separated strings. The end of a message is |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
4 |
* indicated by a double newline - `\n\n`. |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
5 |
* |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
6 |
* For example, a nullary command like PING will be actually sent as `PING\n\n`. |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
7 |
* A unary command, such as `START_GAME nick` will be actually sent as `START_GAME\nnick\n\n`. |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
8 |
*/ |
12133 | 9 |
use nom::*; |
10 |
||
14457 | 11 |
use super::messages::{HWProtocolMessage, HWProtocolMessage::*}; |
12 |
use crate::server::coretypes::{GameCfg, HedgehogInfo, TeamInfo, VoteType, MAX_HEDGEHOGS_PER_TEAM}; |
|
13 |
use std::{ops::Range, str, str::FromStr}; |
|
13796 | 14 |
#[cfg(test)] |
13805 | 15 |
use { |
16 |
super::test::gen_proto_msg, |
|
14457 | 17 |
proptest::{proptest, proptest_helper}, |
13419 | 18 |
}; |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
19 |
|
12133 | 20 |
named!(end_of_message, tag!("\n\n")); |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12140
diff
changeset
|
21 |
named!(str_line<&[u8], &str>, map_res!(not_line_ending, str::from_utf8)); |
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12140
diff
changeset
|
22 |
named!( a_line<&[u8], String>, map!(str_line, String::from)); |
13528 | 23 |
named!(cmd_arg<&[u8], String>, |
24 |
map!(map_res!(take_until_either!(" \n"), str::from_utf8), String::from)); |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12140
diff
changeset
|
25 |
named!( u8_line<&[u8], u8>, map_res!(str_line, FromStr::from_str)); |
13520 | 26 |
named!(u16_line<&[u8], u16>, map_res!(str_line, FromStr::from_str)); |
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12140
diff
changeset
|
27 |
named!(u32_line<&[u8], u32>, map_res!(str_line, FromStr::from_str)); |
13478 | 28 |
named!(yes_no_line<&[u8], bool>, alt!( |
29 |
do_parse!(tag_no_case!("YES") >> (true)) |
|
30 |
| do_parse!(tag_no_case!("NO") >> (false)))); |
|
13438 | 31 |
named!(opt_param<&[u8], Option<String> >, alt!( |
32 |
do_parse!(peek!(tag!("\n\n")) >> (None)) |
|
33 |
| do_parse!(tag!("\n") >> s: str_line >> (Some(s.to_string()))))); |
|
13432 | 34 |
named!(spaces<&[u8], &[u8]>, preceded!(tag!(" "), eat_separator!(" "))); |
13438 | 35 |
named!(opt_space_param<&[u8], Option<String> >, alt!( |
36 |
do_parse!(peek!(tag!("\n\n")) >> (None)) |
|
37 |
| do_parse!(spaces >> s: str_line >> (Some(s.to_string()))))); |
|
13419 | 38 |
named!(hog_line<&[u8], HedgehogInfo>, |
39 |
do_parse!(name: str_line >> eol >> hat: str_line >> |
|
40 |
(HedgehogInfo{name: name.to_string(), hat: hat.to_string()}))); |
|
13795
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
41 |
named!(_8_hogs<&[u8], [HedgehogInfo; MAX_HEDGEHOGS_PER_TEAM as usize]>, |
13419 | 42 |
do_parse!(h1: hog_line >> eol >> h2: hog_line >> eol >> |
43 |
h3: hog_line >> eol >> h4: hog_line >> eol >> |
|
44 |
h5: hog_line >> eol >> h6: hog_line >> eol >> |
|
45 |
h7: hog_line >> eol >> h8: hog_line >> |
|
46 |
([h1, h2, h3, h4, h5, h6, h7, h8]))); |
|
13478 | 47 |
named!(voting<&[u8], VoteType>, alt!( |
48 |
do_parse!(tag_no_case!("KICK") >> spaces >> n: a_line >> |
|
49 |
(VoteType::Kick(n))) |
|
50 |
| do_parse!(tag_no_case!("MAP") >> |
|
51 |
n: opt!(preceded!(spaces, a_line)) >> |
|
52 |
(VoteType::Map(n))) |
|
53 |
| do_parse!(tag_no_case!("PAUSE") >> |
|
54 |
(VoteType::Pause)) |
|
55 |
| do_parse!(tag_no_case!("NEWSEED") >> |
|
56 |
(VoteType::NewSeed)) |
|
57 |
| do_parse!(tag_no_case!("HEDGEHOGS") >> spaces >> n: u8_line >> |
|
58 |
(VoteType::HedgehogsPerTeam(n))))); |
|
12134 | 59 |
|
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
60 |
/** Recognizes messages which do not take any parameters */ |
12133 | 61 |
named!(basic_message<&[u8], HWProtocolMessage>, alt!( |
12135 | 62 |
do_parse!(tag!("PING") >> (Ping)) |
12133 | 63 |
| do_parse!(tag!("PONG") >> (Pong)) |
64 |
| do_parse!(tag!("LIST") >> (List)) |
|
12135 | 65 |
| do_parse!(tag!("BANLIST") >> (BanList)) |
12133 | 66 |
| do_parse!(tag!("GET_SERVER_VAR") >> (GetServerVar)) |
12135 | 67 |
| do_parse!(tag!("TOGGLE_READY") >> (ToggleReady)) |
68 |
| do_parse!(tag!("START_GAME") >> (StartGame)) |
|
13666 | 69 |
| do_parse!(tag!("ROUNDFINISHED") >> _m: opt_param >> (RoundFinished)) |
12135 | 70 |
| do_parse!(tag!("TOGGLE_RESTRICT_JOINS") >> (ToggleRestrictJoin)) |
71 |
| do_parse!(tag!("TOGGLE_RESTRICT_TEAMS") >> (ToggleRestrictTeams)) |
|
12133 | 72 |
| do_parse!(tag!("TOGGLE_REGISTERED_ONLY") >> (ToggleRegisteredOnly)) |
73 |
)); |
|
74 |
||
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
75 |
/** Recognizes messages which take exactly one parameter */ |
12133 | 76 |
named!(one_param_message<&[u8], HWProtocolMessage>, alt!( |
12135 | 77 |
do_parse!(tag!("NICK") >> eol >> n: a_line >> (Nick(n))) |
78 |
| do_parse!(tag!("INFO") >> eol >> n: a_line >> (Info(n))) |
|
79 |
| do_parse!(tag!("CHAT") >> eol >> m: a_line >> (Chat(m))) |
|
13416 | 80 |
| do_parse!(tag!("PART") >> msg: opt_param >> (Part(msg))) |
12135 | 81 |
| do_parse!(tag!("FOLLOW") >> eol >> n: a_line >> (Follow(n))) |
82 |
| do_parse!(tag!("KICK") >> eol >> n: a_line >> (Kick(n))) |
|
83 |
| do_parse!(tag!("UNBAN") >> eol >> n: a_line >> (Unban(n))) |
|
84 |
| do_parse!(tag!("EM") >> eol >> m: a_line >> (EngineMessage(m))) |
|
85 |
| do_parse!(tag!("TEAMCHAT") >> eol >> m: a_line >> (TeamChat(m))) |
|
86 |
| do_parse!(tag!("ROOM_NAME") >> eol >> n: a_line >> (RoomName(n))) |
|
87 |
| do_parse!(tag!("REMOVE_TEAM") >> eol >> n: a_line >> (RemoveTeam(n))) |
|
88 |
||
13520 | 89 |
| do_parse!(tag!("PROTO") >> eol >> d: u16_line >> (Proto(d))) |
12135 | 90 |
|
91 |
| do_parse!(tag!("QUIT") >> msg: opt_param >> (Quit(msg))) |
|
92 |
)); |
|
93 |
||
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
94 |
/** Recognizes messages preceded with CMD */ |
12135 | 95 |
named!(cmd_message<&[u8], HWProtocolMessage>, preceded!(tag!("CMD\n"), alt!( |
96 |
do_parse!(tag_no_case!("STATS") >> (Stats)) |
|
97 |
| do_parse!(tag_no_case!("FIX") >> (Fix)) |
|
98 |
| do_parse!(tag_no_case!("UNFIX") >> (Unfix)) |
|
13432 | 99 |
| do_parse!(tag_no_case!("RESTART_SERVER") >> spaces >> tag!("YES") >> (RestartServer)) |
12135 | 100 |
| do_parse!(tag_no_case!("REGISTERED_ONLY") >> (ToggleServerRegisteredOnly)) |
101 |
| do_parse!(tag_no_case!("SUPER_POWER") >> (SuperPower)) |
|
13432 | 102 |
| do_parse!(tag_no_case!("PART") >> m: opt_space_param >> (Part(m))) |
103 |
| do_parse!(tag_no_case!("QUIT") >> m: opt_space_param >> (Quit(m))) |
|
104 |
| do_parse!(tag_no_case!("DELEGATE") >> spaces >> n: a_line >> (Delegate(n))) |
|
13528 | 105 |
| do_parse!(tag_no_case!("SAVE") >> spaces >> n: cmd_arg >> spaces >> l: cmd_arg >> (Save(n, l))) |
106 |
| do_parse!(tag_no_case!("DELETE") >> spaces >> n: a_line >> (Delete(n))) |
|
13432 | 107 |
| do_parse!(tag_no_case!("SAVEROOM") >> spaces >> r: a_line >> (SaveRoom(r))) |
108 |
| do_parse!(tag_no_case!("LOADROOM") >> spaces >> r: a_line >> (LoadRoom(r))) |
|
109 |
| do_parse!(tag_no_case!("GLOBAL") >> spaces >> m: a_line >> (Global(m))) |
|
110 |
| do_parse!(tag_no_case!("WATCH") >> spaces >> i: a_line >> (Watch(i))) |
|
111 |
| do_parse!(tag_no_case!("GREETING") >> spaces >> m: a_line >> (Greeting(m))) |
|
13478 | 112 |
| do_parse!(tag_no_case!("VOTE") >> spaces >> m: yes_no_line >> (Vote(m))) |
113 |
| do_parse!(tag_no_case!("FORCE") >> spaces >> m: yes_no_line >> (ForceVote(m))) |
|
13432 | 114 |
| do_parse!(tag_no_case!("INFO") >> spaces >> n: a_line >> (Info(n))) |
115 |
| do_parse!(tag_no_case!("MAXTEAMS") >> spaces >> n: u8_line >> (MaxTeams(n))) |
|
13478 | 116 |
| do_parse!(tag_no_case!("CALLVOTE") >> |
117 |
v: opt!(preceded!(spaces, voting)) >> (CallVote(v))) |
|
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
118 |
| do_parse!( |
13432 | 119 |
tag_no_case!("RND") >> alt!(spaces | peek!(end_of_message)) >> |
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
120 |
v: str_line >> |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
121 |
(Rnd(v.split_whitespace().map(String::from).collect()))) |
12135 | 122 |
))); |
123 |
||
124 |
named!(complex_message<&[u8], HWProtocolMessage>, alt!( |
|
125 |
do_parse!(tag!("PASSWORD") >> eol >> |
|
126 |
p: a_line >> eol >> |
|
127 |
s: a_line >> |
|
128 |
(Password(p, s))) |
|
129 |
| do_parse!(tag!("CHECKER") >> eol >> |
|
13798 | 130 |
i: u16_line >> eol >> |
12135 | 131 |
n: a_line >> eol >> |
132 |
p: a_line >> |
|
133 |
(Checker(i, n, p))) |
|
134 |
| do_parse!(tag!("CREATE_ROOM") >> eol >> |
|
135 |
n: a_line >> |
|
136 |
p: opt_param >> |
|
137 |
(CreateRoom(n, p))) |
|
13416 | 138 |
| do_parse!(tag!("JOIN_ROOM") >> eol >> |
12135 | 139 |
n: a_line >> |
140 |
p: opt_param >> |
|
13416 | 141 |
(JoinRoom(n, p))) |
13419 | 142 |
| do_parse!(tag!("ADD_TEAM") >> eol >> |
143 |
name: a_line >> eol >> |
|
144 |
color: u8_line >> eol >> |
|
145 |
grave: a_line >> eol >> |
|
146 |
fort: a_line >> eol >> |
|
147 |
voice_pack: a_line >> eol >> |
|
148 |
flag: a_line >> eol >> |
|
149 |
difficulty: u8_line >> eol >> |
|
150 |
hedgehogs: _8_hogs >> |
|
13524 | 151 |
(AddTeam(Box::new(TeamInfo{ |
13419 | 152 |
name, color, grave, fort, |
153 |
voice_pack, flag, difficulty, |
|
154 |
hedgehogs, hedgehogs_number: 0 |
|
13524 | 155 |
})))) |
13419 | 156 |
| do_parse!(tag!("HH_NUM") >> eol >> |
157 |
n: a_line >> eol >> |
|
158 |
c: u8_line >> |
|
159 |
(SetHedgehogsNumber(n, c))) |
|
160 |
| do_parse!(tag!("TEAM_COLOR") >> eol >> |
|
161 |
n: a_line >> eol >> |
|
162 |
c: u8_line >> |
|
163 |
(SetTeamColor(n, c))) |
|
12135 | 164 |
| do_parse!(tag!("BAN") >> eol >> |
165 |
n: a_line >> eol >> |
|
166 |
r: a_line >> eol >> |
|
167 |
t: u32_line >> |
|
168 |
(Ban(n, r, t))) |
|
169 |
| do_parse!(tag!("BAN_IP") >> eol >> |
|
170 |
n: a_line >> eol >> |
|
171 |
r: a_line >> eol >> |
|
172 |
t: u32_line >> |
|
173 |
(BanIP(n, r, t))) |
|
174 |
| do_parse!(tag!("BAN_NICK") >> eol >> |
|
175 |
n: a_line >> eol >> |
|
176 |
r: a_line >> eol >> |
|
177 |
t: u32_line >> |
|
178 |
(BanNick(n, r, t))) |
|
12133 | 179 |
)); |
180 |
||
13422 | 181 |
named!(cfg_message<&[u8], HWProtocolMessage>, preceded!(tag!("CFG\n"), map!(alt!( |
182 |
do_parse!(tag!("THEME") >> eol >> |
|
183 |
name: a_line >> |
|
184 |
(GameCfg::Theme(name))) |
|
185 |
| do_parse!(tag!("SCRIPT") >> eol >> |
|
186 |
name: a_line >> |
|
187 |
(GameCfg::Script(name))) |
|
188 |
| do_parse!(tag!("AMMO") >> eol >> |
|
189 |
name: a_line >> |
|
190 |
value: opt_param >> |
|
191 |
(GameCfg::Ammo(name, value))) |
|
192 |
| do_parse!(tag!("SCHEME") >> eol >> |
|
13441 | 193 |
name: a_line >> |
194 |
values: opt!(preceded!(eol, separated_list!(eol, a_line))) >> |
|
14350 | 195 |
(GameCfg::Scheme(name, values.unwrap_or_default()))) |
13422 | 196 |
| do_parse!(tag!("FEATURE_SIZE") >> eol >> |
197 |
value: u32_line >> |
|
198 |
(GameCfg::FeatureSize(value))) |
|
199 |
| do_parse!(tag!("MAP") >> eol >> |
|
200 |
value: a_line >> |
|
201 |
(GameCfg::MapType(value))) |
|
202 |
| do_parse!(tag!("MAPGEN") >> eol >> |
|
203 |
value: u32_line >> |
|
204 |
(GameCfg::MapGenerator(value))) |
|
205 |
| do_parse!(tag!("MAZE_SIZE") >> eol >> |
|
206 |
value: u32_line >> |
|
207 |
(GameCfg::MazeSize(value))) |
|
208 |
| do_parse!(tag!("SEED") >> eol >> |
|
209 |
value: a_line >> |
|
210 |
(GameCfg::Seed(value))) |
|
211 |
| do_parse!(tag!("TEMPLATE") >> eol >> |
|
212 |
value: u32_line >> |
|
213 |
(GameCfg::Template(value))) |
|
214 |
| do_parse!(tag!("DRAWNMAP") >> eol >> |
|
215 |
value: a_line >> |
|
216 |
(GameCfg::DrawnMap(value))) |
|
217 |
), Cfg))); |
|
218 |
||
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
219 |
named!(malformed_message<&[u8], HWProtocolMessage>, |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
220 |
do_parse!(separated_list!(eol, a_line) >> (Malformed))); |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
221 |
|
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
222 |
named!(empty_message<&[u8], HWProtocolMessage>, |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
223 |
do_parse!(alt!(end_of_message | eol) >> (Empty))); |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
224 |
|
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
225 |
named!(message<&[u8], HWProtocolMessage>, alt!(terminated!( |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
226 |
alt!( |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
227 |
basic_message |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
228 |
| one_param_message |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
229 |
| cmd_message |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
230 |
| complex_message |
13422 | 231 |
| cfg_message |
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
232 |
), end_of_message |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
233 |
) |
12140 | 234 |
| terminated!(malformed_message, end_of_message) |
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
235 |
| empty_message |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
236 |
) |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12136
diff
changeset
|
237 |
); |
12133 | 238 |
|
12136 | 239 |
named!(pub extract_messages<&[u8], Vec<HWProtocolMessage> >, many0!(complete!(message))); |
12133 | 240 |
|
13796 | 241 |
#[cfg(test)] |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
242 |
proptest! { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
243 |
#[test] |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
244 |
fn is_parser_composition_idempotent(ref msg in gen_proto_msg()) { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
245 |
println!("!! Msg: {:?}, Bytes: {:?} !!", msg, msg.to_raw_protocol().as_bytes()); |
13438 | 246 |
assert_eq!(message(msg.to_raw_protocol().as_bytes()), Ok((&b""[..], msg.clone()))) |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
247 |
} |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
248 |
} |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
249 |
|
12133 | 250 |
#[test] |
251 |
fn parse_test() { |
|
14457 | 252 |
assert_eq!(message(b"PING\n\n"), Ok((&b""[..], Ping))); |
253 |
assert_eq!(message(b"START_GAME\n\n"), Ok((&b""[..], StartGame))); |
|
254 |
assert_eq!( |
|
255 |
message(b"NICK\nit's me\n\n"), |
|
256 |
Ok((&b""[..], Nick("it's me".to_string()))) |
|
257 |
); |
|
258 |
assert_eq!(message(b"PROTO\n51\n\n"), Ok((&b""[..], Proto(51)))); |
|
259 |
assert_eq!( |
|
260 |
message(b"QUIT\nbye-bye\n\n"), |
|
261 |
Ok((&b""[..], Quit(Some("bye-bye".to_string())))) |
|
262 |
); |
|
263 |
assert_eq!(message(b"QUIT\n\n"), Ok((&b""[..], Quit(None)))); |
|
264 |
assert_eq!( |
|
265 |
message(b"CMD\nwatch demo\n\n"), |
|
266 |
Ok((&b""[..], Watch("demo".to_string()))) |
|
267 |
); |
|
268 |
assert_eq!( |
|
269 |
message(b"BAN\nme\nbad\n77\n\n"), |
|
270 |
Ok((&b""[..], Ban("me".to_string(), "bad".to_string(), 77))) |
|
271 |
); |
|
12136 | 272 |
|
14457 | 273 |
assert_eq!(message(b"CMD\nPART\n\n"), Ok((&b""[..], Part(None)))); |
274 |
assert_eq!( |
|
275 |
message(b"CMD\nPART _msg_\n\n"), |
|
276 |
Ok((&b""[..], Part(Some("_msg_".to_string())))) |
|
277 |
); |
|
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12142
diff
changeset
|
278 |
|
13438 | 279 |
assert_eq!(message(b"CMD\nRND\n\n"), Ok((&b""[..], Rnd(vec![])))); |
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
280 |
assert_eq!( |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
281 |
message(b"CMD\nRND A B\n\n"), |
13438 | 282 |
Ok((&b""[..], Rnd(vec![String::from("A"), String::from("B")]))) |
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
283 |
); |
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
284 |
|
14457 | 285 |
assert_eq!( |
286 |
extract_messages(b"QUIT\n1\n2\n\n"), |
|
287 |
Ok((&b""[..], vec![Malformed])) |
|
288 |
); |
|
12140 | 289 |
|
14457 | 290 |
assert_eq!( |
291 |
extract_messages(b"PING\n\nPING\n\nP"), |
|
292 |
Ok((&b"P"[..], vec![Ping, Ping])) |
|
293 |
); |
|
294 |
assert_eq!( |
|
295 |
extract_messages(b"SING\n\nPING\n\n"), |
|
296 |
Ok((&b""[..], vec![Malformed, Ping])) |
|
297 |
); |
|
298 |
assert_eq!( |
|
299 |
extract_messages(b"\n\n\n\nPING\n\n"), |
|
300 |
Ok((&b""[..], vec![Empty, Empty, Ping])) |
|
301 |
); |
|
302 |
assert_eq!( |
|
303 |
extract_messages(b"\n\n\nPING\n\n"), |
|
304 |
Ok((&b""[..], vec![Empty, Empty, Ping])) |
|
305 |
); |
|
13431
6a818f9192f4
Implement parsing for rnd and add a little documentation
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13423
diff
changeset
|
306 |
} |