diff options
| author | Zeyla Hellyer <[email protected]> | 2018-08-01 08:08:23 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-08-01 08:10:05 -0700 |
| commit | 3fed313193356c6784a33b79d1c2f583ea3944f9 (patch) | |
| tree | 875b4bab989fc573850d30317a1797bca5027e9f /src/model/channel | |
| parent | Reword the inner doc comment in `complex_bucket` (diff) | |
| download | serenity-3fed313193356c6784a33b79d1c2f583ea3944f9.tar.xz serenity-3fed313193356c6784a33b79d1c2f583ea3944f9.zip | |
Move unit tests into source
Move the unit tests into the relevant source files. There's no need for them to
be seprate, especially when the `tests` directory is meant to be for integration
tests.
The deserialization tests that include JSON files are still in the `tests` dir,
along with the public prelude re-export tests.
Diffstat (limited to 'src/model/channel')
| -rw-r--r-- | src/model/channel/mod.rs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index 8d586a6..e0ef085 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -677,3 +677,93 @@ pub enum PermissionOverwriteType { /// A role which is having its permission overwrites edited. Role(RoleId), } + +#[cfg(test)] +mod test { + #[cfg(feature = "utils")] + mod utils { + use model::prelude::*; + use parking_lot::RwLock; + use std::collections::HashMap; + use std::sync::Arc; + + fn group() -> Group { + Group { + channel_id: ChannelId(1), + icon: None, + last_message_id: None, + last_pin_timestamp: None, + name: None, + owner_id: UserId(2), + recipients: HashMap::new(), + } + } + + fn guild_channel() -> GuildChannel { + GuildChannel { + id: ChannelId(1), + bitrate: None, + category_id: None, + guild_id: GuildId(2), + kind: ChannelType::Text, + last_message_id: None, + last_pin_timestamp: None, + name: "nsfw-stuff".to_string(), + permission_overwrites: vec![], + position: 0, + topic: None, + user_limit: None, + nsfw: false, + } + } + + fn private_channel() -> PrivateChannel { + PrivateChannel { + id: ChannelId(1), + last_message_id: None, + last_pin_timestamp: None, + kind: ChannelType::Private, + recipient: Arc::new(RwLock::new(User { + id: UserId(2), + avatar: None, + bot: false, + discriminator: 1, + name: "ab".to_string(), + })), + } + } + + #[test] + fn nsfw_checks() { + let mut channel = guild_channel(); + assert!(channel.is_nsfw()); + channel.kind = ChannelType::Voice; + assert!(!channel.is_nsfw()); + + channel.kind = ChannelType::Text; + channel.name = "nsfw-".to_string(); + assert!(!channel.is_nsfw()); + + channel.name = "nsfw".to_string(); + assert!(channel.is_nsfw()); + channel.kind = ChannelType::Voice; + assert!(!channel.is_nsfw()); + channel.kind = ChannelType::Text; + + channel.name = "nsf".to_string(); + channel.nsfw = true; + assert!(channel.is_nsfw()); + channel.nsfw = false; + assert!(!channel.is_nsfw()); + + let channel = Channel::Guild(Arc::new(RwLock::new(channel))); + assert!(!channel.is_nsfw()); + + let group = group(); + assert!(!group.is_nsfw()); + + let private_channel = private_channel(); + assert!(!private_channel.is_nsfw()); + } + } +} |