rust/hedgewars-server/src/protocol/parser.rs
changeset 14782 8015a6e4ca3c
parent 14780 09d46ab83361
child 14788 b3adc030104b
--- a/rust/hedgewars-server/src/protocol/parser.rs	Mon Apr 08 23:05:54 2019 +0200
+++ b/rust/hedgewars-server/src/protocol/parser.rs	Tue Apr 09 00:06:53 2019 +0300
@@ -17,12 +17,6 @@
 use super::messages::{HWProtocolMessage, HWProtocolMessage::*};
 use crate::server::coretypes::{GameCfg, HedgehogInfo, TeamInfo, VoteType, MAX_HEDGEHOGS_PER_TEAM};
 
-#[cfg(test)]
-use {
-    super::test::gen_proto_msg,
-    proptest::{proptest, proptest_helper},
-};
-
 #[derive(Debug, PartialEq)]
 pub struct HWProtocolError {}
 
@@ -548,68 +542,75 @@
 }
 
 #[cfg(test)]
-proptest! {
+mod test {
+    use super::{extract_messages, message};
+    use crate::protocol::{messages::HWProtocolMessage::*, test::gen_proto_msg};
+    use proptest::{proptest, proptest_helper};
+
+    #[cfg(test)]
+    proptest! {
+        #[test]
+        fn is_parser_composition_idempotent(ref msg in gen_proto_msg()) {
+            println!("!! Msg: {:?}, Bytes: {:?} !!", msg, msg.to_raw_protocol().as_bytes());
+            assert_eq!(message(msg.to_raw_protocol().as_bytes()), Ok((&b""[..], msg.clone())))
+        }
+    }
+
     #[test]
-    fn is_parser_composition_idempotent(ref msg in gen_proto_msg()) {
-        println!("!! Msg: {:?}, Bytes: {:?} !!", msg, msg.to_raw_protocol().as_bytes());
-        assert_eq!(message(msg.to_raw_protocol().as_bytes()), Ok((&b""[..], msg.clone())))
+    fn parse_test() {
+        assert_eq!(message(b"PING\n\n"), Ok((&b""[..], Ping)));
+        assert_eq!(message(b"START_GAME\n\n"), Ok((&b""[..], StartGame)));
+        assert_eq!(
+            message(b"NICK\nit's me\n\n"),
+            Ok((&b""[..], Nick("it's me".to_string())))
+        );
+        assert_eq!(message(b"PROTO\n51\n\n"), Ok((&b""[..], Proto(51))));
+        assert_eq!(
+            message(b"QUIT\nbye-bye\n\n"),
+            Ok((&b""[..], Quit(Some("bye-bye".to_string()))))
+        );
+        assert_eq!(message(b"QUIT\n\n"), Ok((&b""[..], Quit(None))));
+        assert_eq!(
+            message(b"CMD\nwatch demo\n\n"),
+            Ok((&b""[..], Watch("demo".to_string())))
+        );
+        assert_eq!(
+            message(b"BAN\nme\nbad\n77\n\n"),
+            Ok((&b""[..], Ban("me".to_string(), "bad".to_string(), 77)))
+        );
+
+        assert_eq!(message(b"CMD\nPART\n\n"), Ok((&b""[..], Part(None))));
+        assert_eq!(
+            message(b"CMD\nPART _msg_\n\n"),
+            Ok((&b""[..], Part(Some("_msg_".to_string()))))
+        );
+
+        assert_eq!(message(b"CMD\nRND\n\n"), Ok((&b""[..], Rnd(vec![]))));
+        assert_eq!(
+            message(b"CMD\nRND A B\n\n"),
+            Ok((&b""[..], Rnd(vec![String::from("A"), String::from("B")])))
+        );
+
+        assert_eq!(
+            extract_messages(b"QUIT\n1\n2\n\n"),
+            Ok((&b""[..], vec![Malformed]))
+        );
+
+        assert_eq!(
+            extract_messages(b"PING\n\nPING\n\nP"),
+            Ok((&b"P"[..], vec![Ping, Ping]))
+        );
+        assert_eq!(
+            extract_messages(b"SING\n\nPING\n\n"),
+            Ok((&b""[..], vec![Malformed, Ping]))
+        );
+        assert_eq!(
+            extract_messages(b"\n\n\n\nPING\n\n"),
+            Ok((&b""[..], vec![Empty, Empty, Ping]))
+        );
+        assert_eq!(
+            extract_messages(b"\n\n\nPING\n\n"),
+            Ok((&b""[..], vec![Empty, Empty, Ping]))
+        );
     }
 }
-
-#[test]
-fn parse_test() {
-    assert_eq!(message(b"PING\n\n"), Ok((&b""[..], Ping)));
-    assert_eq!(message(b"START_GAME\n\n"), Ok((&b""[..], StartGame)));
-    assert_eq!(
-        message(b"NICK\nit's me\n\n"),
-        Ok((&b""[..], Nick("it's me".to_string())))
-    );
-    assert_eq!(message(b"PROTO\n51\n\n"), Ok((&b""[..], Proto(51))));
-    assert_eq!(
-        message(b"QUIT\nbye-bye\n\n"),
-        Ok((&b""[..], Quit(Some("bye-bye".to_string()))))
-    );
-    assert_eq!(message(b"QUIT\n\n"), Ok((&b""[..], Quit(None))));
-    assert_eq!(
-        message(b"CMD\nwatch demo\n\n"),
-        Ok((&b""[..], Watch("demo".to_string())))
-    );
-    assert_eq!(
-        message(b"BAN\nme\nbad\n77\n\n"),
-        Ok((&b""[..], Ban("me".to_string(), "bad".to_string(), 77)))
-    );
-
-    assert_eq!(message(b"CMD\nPART\n\n"), Ok((&b""[..], Part(None))));
-    assert_eq!(
-        message(b"CMD\nPART _msg_\n\n"),
-        Ok((&b""[..], Part(Some("_msg_".to_string()))))
-    );
-
-    assert_eq!(message(b"CMD\nRND\n\n"), Ok((&b""[..], Rnd(vec![]))));
-    assert_eq!(
-        message(b"CMD\nRND A B\n\n"),
-        Ok((&b""[..], Rnd(vec![String::from("A"), String::from("B")])))
-    );
-
-    assert_eq!(
-        extract_messages(b"QUIT\n1\n2\n\n"),
-        Ok((&b""[..], vec![Malformed]))
-    );
-
-    assert_eq!(
-        extract_messages(b"PING\n\nPING\n\nP"),
-        Ok((&b"P"[..], vec![Ping, Ping]))
-    );
-    assert_eq!(
-        extract_messages(b"SING\n\nPING\n\n"),
-        Ok((&b""[..], vec![Malformed, Ping]))
-    );
-    assert_eq!(
-        extract_messages(b"\n\n\n\nPING\n\n"),
-        Ok((&b""[..], vec![Empty, Empty, Ping]))
-    );
-    assert_eq!(
-        extract_messages(b"\n\n\nPING\n\n"),
-        Ok((&b""[..], vec![Empty, Empty, Ping]))
-    );
-}