Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
4e554c4c committed Oct 18, 2024
1 parent 9637d64 commit 4c75e7a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions irc/proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,47 @@ macro_rules! command {
$crate::command($c, vec![$($p.into(),)*])
);
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn is_channel_correct() {
let chantypes = DEFAULT_CHANNEL_PREFIXES;
assert!(is_channel("#foo", chantypes));
assert!(is_channel("&foo", chantypes));
assert!(!is_channel("foo", chantypes));
}

#[test]
fn empty_chantypes() {
assert!(!is_channel("#foo", &[]));
assert!(!is_channel("&foo", &[]));
}

#[test]
fn parse_channel() {
let chantypes = DEFAULT_CHANNEL_PREFIXES;
let prefixes = CHANNEL_MEMBERSHIP_PREFIXES;
assert_eq!(
parse_channel_from_target("#foo", chantypes, prefixes),
Some((vec![], "#foo".to_owned()))
);
assert_eq!(
parse_channel_from_target("+%#foo", chantypes, prefixes),
Some((vec!['+', '%'], "#foo".to_owned()))
);
assert_eq!(
parse_channel_from_target("&+%foo", chantypes, prefixes),
Some((vec![], "&+%foo".to_owned()))
);
}

#[test]
fn invalid_channels() {
let chantypes = DEFAULT_CHANNEL_PREFIXES;
let prefixes = CHANNEL_MEMBERSHIP_PREFIXES;
assert!(parse_channel_from_target("+%foo", chantypes, prefixes).is_none());
}
}

0 comments on commit 4c75e7a

Please sign in to comment.