aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs
blob: 88c6f29e2942f20b3a44edaab1a609d0ed1f4137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use azalea_brigadier::suggestion::Suggestions;
use azalea_buf::McBuf;
use azalea_chat::FormattedText;
use azalea_protocol_macros::ClientboundGamePacket;

#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundCommandSuggestionsPacket {
    #[var]
    pub id: u32,
    pub suggestions: Suggestions<FormattedText>,
}

#[cfg(test)]
mod tests {
    use super::*;
    use azalea_brigadier::{context::StringRange, suggestion::Suggestion};
    use azalea_buf::{McBufReadable, McBufWritable};
    use std::io::Cursor;

    #[test]
    fn test_suggestions() {
        let suggestions = Suggestions {
            range: StringRange::new(0, 5),
            suggestions: vec![Suggestion {
                text: "foo".to_string(),
                range: StringRange::new(1, 4),
                tooltip: Some(FormattedText::from("bar".to_string())),
            }],
        };
        let mut buf = Vec::new();
        suggestions.write_into(&mut buf).unwrap();
        let mut cursor = Cursor::new(&buf[..]);
        let suggestions = Suggestions::read_from(&mut cursor).unwrap();
        assert_eq!(suggestions, suggestions);
    }
}