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