aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-08-07 09:24:07 -0700
committerZeyla Hellyer <[email protected]>2018-08-07 09:25:06 -0700
commit39bb75cc6759ceb972c0caca0b03c7971a445eb8 (patch)
tree343d97399ea597804f0cd30016034c4adb8efebe /src/model
parentFix some documentation spacing (diff)
downloadserenity-39bb75cc6759ceb972c0caca0b03c7971a445eb8.tar.xz
serenity-39bb75cc6759ceb972c0caca0b03c7971a445eb8.zip
Fix compilation + tests on certain feature combos
On certain feature combinations, compilation and tests would not function correctly. This commit goes through a number of feature combinations and gates some tests behind the required features and fixes other compilation errors.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel/mod.rs42
-rw-r--r--src/model/misc.rs130
2 files changed, 104 insertions, 68 deletions
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs
index 9b350e5..5ba9a87 100644
--- a/src/model/channel/mod.rs
+++ b/src/model/channel/mod.rs
@@ -69,9 +69,13 @@ impl Channel {
///
/// ```rust,no_run
/// # extern crate serenity;
+ /// #
/// # use self::serenity::model::id::ChannelId;
+ /// #
+ /// # #[cfg(feature = "model")]
/// # fn main() {
- /// # let channel = ChannelId(0).get().unwrap();
+ /// # let channel = ChannelId(0).get().unwrap();
+ /// #
/// match channel.group() {
/// Some(group_lock) => {
/// if let Some(ref name) = group_lock.read().name {
@@ -82,7 +86,11 @@ impl Channel {
/// },
/// None => { println!("It's not a group!"); },
/// }
+ /// #
/// # }
+ /// #
+ /// # #[cfg(not(feature = "model"))]
+ /// fn main() {}
/// ```
pub fn group(self) -> Option<Arc<RwLock<Group>>> {
match self {
@@ -103,16 +111,24 @@ impl Channel {
///
/// ```rust,no_run
/// # extern crate serenity;
+ /// #
/// # use self::serenity::model::id::ChannelId;
+ /// #
+ /// # #[cfg(feature = "model")]
/// # fn main() {
- /// let channel = ChannelId(0).get().unwrap();
+ /// # let channel = ChannelId(0).get().unwrap();
+ /// #
/// match channel.guild() {
/// Some(guild_lock) => {
/// println!("It's a guild named {}!", guild_lock.read().name);
/// },
/// None => { println!("It's not a guild!"); },
/// }
+ /// #
/// # }
+ /// #
+ /// # #[cfg(not(feature = "model"))]
+ /// fn main() {}
/// ```
pub fn guild(self) -> Option<Arc<RwLock<GuildChannel>>> {
match self {
@@ -133,9 +149,13 @@ impl Channel {
///
/// ```rust,no_run
/// # extern crate serenity;
+ /// #
/// # use self::serenity::model::id::ChannelId;
+ /// #
+ /// # #[cfg(feature = "model")]
/// # fn main() {
- /// # let channel = ChannelId(0).get().unwrap();
+ /// # let channel = ChannelId(0).get().unwrap();
+ /// #
/// match channel.private() {
/// Some(private_lock) => {
/// let private = private_lock.read();
@@ -145,7 +165,11 @@ impl Channel {
/// },
/// None => { println!("It's not a private channel!"); },
/// }
+ /// #
/// # }
+ /// #
+ /// # #[cfg(not(feature = "model"))]
+ /// fn main() {}
/// ```
pub fn private(self) -> Option<Arc<RwLock<PrivateChannel>>> {
match self {
@@ -166,16 +190,24 @@ impl Channel {
///
/// ```rust,no_run
/// # extern crate serenity;
+ /// #
/// # use self::serenity::model::id::ChannelId;
+ /// #
+ /// # #[cfg(feature = "model")]
/// # fn main() {
/// # let channel = ChannelId(0).get().unwrap();
+ /// #
/// match channel.category() {
/// Some(category_lock) => {
/// println!("It's a category named {}!", category_lock.read().name);
/// },
/// None => { println!("It's not a category!"); },
/// }
+ /// #
/// # }
+ /// #
+ /// # #[cfg(not(feature = "model"))]
+ /// fn main() {}
/// ```
pub fn category(self) -> Option<Arc<RwLock<ChannelCategory>>> {
match self {
@@ -674,8 +706,8 @@ pub enum PermissionOverwriteType {
#[cfg(test)]
mod test {
- #[cfg(feature = "utils")]
- mod utils {
+ #[cfg(all(feature = "model", feature = "utils"))]
+ mod model_utils {
use model::prelude::*;
use parking_lot::RwLock;
use std::collections::HashMap;
diff --git a/src/model/misc.rs b/src/model/misc.rs
index 62a002a..5c0825a 100644
--- a/src/model/misc.rs
+++ b/src/model/misc.rs
@@ -312,9 +312,6 @@ pub struct Maintenance {
#[cfg(test)]
mod test {
use model::prelude::*;
- use parking_lot::RwLock;
- use std::sync::Arc;
- use utils::Colour;
#[test]
fn test_formatters() {
@@ -326,65 +323,72 @@ mod test {
}
#[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>");
+ mod utils {
+ use model::prelude::*;
+ use parking_lot::RwLock;
+ use std::sync::Arc;
+ use utils::Colour;
+
+ #[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>");
+ }
}
}