ellidri_tokens/
lib.rs

1//! Parse IRC like a boss.
2//!
3//! This library provides helpers to tokenize and build IRC messages, while keeping the number of
4//! allocations minimal.
5
6pub use buffers::{Buffer, MessageBuffer, TagBuffer};
7pub use command::Command;
8pub use message::{
9    MESSAGE_LENGTH,
10    Message,
11    PARAMS_LENGTH,
12    Tag,
13    tag_escape,
14    tags,
15};
16
17mod buffers;
18mod command;
19mod message;
20pub mod mode;
21pub mod rpl;
22
23/// Assert all data of a message.
24///
25/// Empty elements in `params` will not be asserted with their equivalent in `msg.params`, but will
26/// still count for the assertion of the number of parameters.
27pub fn assert_msg(msg: &Message<'_>, prefix: Option<&str>, command: Result<Command, &str>,
28                  params: &[&str])
29{
30    assert_eq!(msg.prefix, prefix, "prefix of {:?}", msg);
31    assert_eq!(msg.command, command, "command of {:?}", msg);
32    assert_eq!(msg.num_params, params.len(), "number of parameters of {:?}", msg);
33    for (i, (actual, expected)) in msg.params.iter().zip(params.iter()).enumerate() {
34        if expected.is_empty() {
35            // Some parameters may be of different form every time they are generated (e.g.
36            // NAMREPLY params, since the order comes from `HashMap::iter`), so we skip them.
37            continue;
38        }
39        assert_eq!(actual, expected, "parameter #{} of {:?}", i, msg);
40    }
41}