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