rust/hedgewars-network-protocol/src/tests/parser.rs
changeset 15997 7c8697fa019f
parent 15830 ea459da15b30
equal deleted inserted replaced
15996:19927b70588c 15997:7c8697fa019f
     1 use crate::{
     1 use crate::{
     2     parser::HwProtocolError,
     2     parser::HwProtocolError,
     3     parser::{message, server_message},
     3     parser::{malformed_message, message, server_message},
     4     types::GameCfg,
     4     types::GameCfg,
     5 };
     5 };
     6 
     6 
     7 #[test]
     7 #[test]
     8 fn parse_test() {
     8 fn parse_test() {
     9     use crate::messages::HwProtocolMessage::*;
     9     use crate::messages::HwProtocolMessage::*;
       
    10     use nom::Err::Incomplete;
       
    11 
       
    12     assert!(matches!(
       
    13         dbg!(message(b"CHAT\nWhat the")),
       
    14         Err(Incomplete(_))
       
    15     ));
       
    16     assert!(matches!(
       
    17         dbg!(malformed_message(b"CHAT\nWhat the \xF0\x9F\xA6\x94\n\nBYE")),
       
    18         Ok((b"BYE", _))
       
    19     ));
    10 
    20 
    11     assert_eq!(message(b"PING\n\n"), Ok((&b""[..], Ping)));
    21     assert_eq!(message(b"PING\n\n"), Ok((&b""[..], Ping)));
    12     assert_eq!(message(b"START_GAME\n\n"), Ok((&b""[..], StartGame)));
    22     assert_eq!(message(b"START_GAME\n\n"), Ok((&b""[..], StartGame)));
    13     assert_eq!(
    23     assert_eq!(
    14         message(b"NICK\nit's me\n\n"),
    24         message(b"NICK\nit's me\n\n"),