equal
deleted
inserted
replaced
97 r: a_line >> eol >> |
97 r: a_line >> eol >> |
98 t: u32_line >> |
98 t: u32_line >> |
99 (BanNick(n, r, t))) |
99 (BanNick(n, r, t))) |
100 )); |
100 )); |
101 |
101 |
102 named!(message<&[u8],HWProtocolMessage>, terminated!(alt!( |
102 named!(message<&[u8], HWProtocolMessage>, terminated!(alt!( |
103 basic_message |
103 basic_message |
104 | one_param_message |
104 | one_param_message |
105 | cmd_message |
105 | cmd_message |
106 | complex_message |
106 | complex_message |
107 ), end_of_message |
107 ), end_of_message |
108 )); |
108 )); |
109 |
109 |
|
110 named!(pub extract_messages<&[u8], Vec<HWProtocolMessage> >, many0!(complete!(message))); |
110 |
111 |
111 #[test] |
112 #[test] |
112 fn parse_test() { |
113 fn parse_test() { |
113 assert_eq!(message(b"PING\n\n"), IResult::Done(&b""[..], Ping)); |
114 assert_eq!(message(b"PING\n\n"), IResult::Done(&b""[..], Ping)); |
114 assert_eq!(message(b"START_GAME\n\n"), IResult::Done(&b""[..], StartGame)); |
115 assert_eq!(message(b"START_GAME\n\n"), IResult::Done(&b""[..], StartGame)); |
116 assert_eq!(message(b"PROTO\n51\n\n"), IResult::Done(&b""[..], Proto(51))); |
117 assert_eq!(message(b"PROTO\n51\n\n"), IResult::Done(&b""[..], Proto(51))); |
117 assert_eq!(message(b"QUIT\nbye-bye\n\n"), IResult::Done(&b""[..], Quit(Some("bye-bye")))); |
118 assert_eq!(message(b"QUIT\nbye-bye\n\n"), IResult::Done(&b""[..], Quit(Some("bye-bye")))); |
118 assert_eq!(message(b"QUIT\n\n"), IResult::Done(&b""[..], Quit(None))); |
119 assert_eq!(message(b"QUIT\n\n"), IResult::Done(&b""[..], Quit(None))); |
119 assert_eq!(message(b"CMD\nwatch\ndemo\n\n"), IResult::Done(&b""[..], Watch("demo"))); |
120 assert_eq!(message(b"CMD\nwatch\ndemo\n\n"), IResult::Done(&b""[..], Watch("demo"))); |
120 assert_eq!(message(b"BAN\nme\nbad\n77\n\n"), IResult::Done(&b""[..], Ban("me", "bad", 77))); |
121 assert_eq!(message(b"BAN\nme\nbad\n77\n\n"), IResult::Done(&b""[..], Ban("me", "bad", 77))); |
|
122 |
|
123 assert_eq!(extract_messages(b"PING\n\nPING\n\nP"), IResult::Done(&b"P"[..], vec![Ping, Ping])); |
121 } |
124 } |