aboutsummaryrefslogtreecommitdiff
path: root/src/model/misc.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-08-01 08:08:23 -0700
committerZeyla Hellyer <[email protected]>2018-08-01 08:10:05 -0700
commit3fed313193356c6784a33b79d1c2f583ea3944f9 (patch)
tree875b4bab989fc573850d30317a1797bca5027e9f /src/model/misc.rs
parentReword the inner doc comment in `complex_bucket` (diff)
downloadserenity-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/misc.rs')
-rw-r--r--src/model/misc.rs80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/model/misc.rs b/src/model/misc.rs
index 3195c55..62a002a 100644
--- a/src/model/misc.rs
+++ b/src/model/misc.rs
@@ -308,3 +308,83 @@ pub struct Maintenance {
pub start: String,
pub stop: String,
}
+
+#[cfg(test)]
+mod test {
+ use model::prelude::*;
+ use parking_lot::RwLock;
+ use std::sync::Arc;
+ use utils::Colour;
+
+ #[test]
+ fn test_formatters() {
+ assert_eq!(ChannelId(1).to_string(), "1");
+ assert_eq!(EmojiId(2).to_string(), "2");
+ assert_eq!(GuildId(3).to_string(), "3");
+ assert_eq!(RoleId(4).to_string(), "4");
+ assert_eq!(UserId(5).to_string(), "5");
+ }
+
+ #[cfg(feature = "utils")]
+ #[test]
+ fn test_mention() {
+ let channel = Channel::Guild(Arc::new(RwLock::new(GuildChannel {
+ bitrate: None,
+ category_id: None,
+ guild_id: GuildId(1),
+ kind: ChannelType::Text,
+ id: ChannelId(4),
+ last_message_id: None,
+ last_pin_timestamp: None,
+ name: "a".to_string(),
+ permission_overwrites: vec![],
+ position: 1,
+ topic: None,
+ user_limit: None,
+ nsfw: false,
+ })));
+ let emoji = Emoji {
+ animated: false,
+ id: EmojiId(5),
+ name: "a".to_string(),
+ managed: true,
+ require_colons: true,
+ roles: vec![],
+ };
+ let role = Role {
+ id: RoleId(2),
+ colour: Colour::ROSEWATER,
+ hoist: false,
+ managed: false,
+ mentionable: false,
+ name: "fake role".to_string(),
+ permissions: Permissions::empty(),
+ position: 1,
+ };
+ let user = User {
+ id: UserId(6),
+ avatar: None,
+ bot: false,
+ discriminator: 4132,
+ name: "fake".to_string(),
+ };
+ let member = Member {
+ deaf: false,
+ guild_id: GuildId(2),
+ joined_at: None,
+ mute: false,
+ nick: None,
+ roles: vec![],
+ user: Arc::new(RwLock::new(user.clone())),
+ };
+
+ assert_eq!(ChannelId(1).mention(), "<#1>");
+ assert_eq!(channel.mention(), "<#4>");
+ assert_eq!(emoji.mention(), "<:a:5>");
+ assert_eq!(member.mention(), "<@6>");
+ assert_eq!(role.mention(), "<@&2>");
+ assert_eq!(role.id.mention(), "<@&2>");
+ assert_eq!(user.mention(), "<@6>");
+ assert_eq!(user.id.mention(), "<@6>");
+ }
+}