-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more emoji features + valid url testing
- Loading branch information
1 parent
9c06170
commit a47d8fd
Showing
7 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "serenity_discord_bot_derive" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
quote = "1.0.37" | ||
syn = "2.0.90" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
|
||
// Credit: | ||
// https://stackoverflow.com/questions/68025264/how-to-get-all-the-variants-of-an-enum-in-a-vect-with-a-proc-macro/69812881#69812881 | ||
#[proc_macro_derive(IterateVariants)] | ||
pub fn derive_all_variants(input: TokenStream) -> TokenStream { | ||
let ast = syn::parse_macro_input!(input as syn::DeriveInput); | ||
|
||
let syn::Data::Enum(enum_item) = ast.data else { | ||
return quote!(compile_error!("AllVariants only works on enums")).into(); | ||
}; | ||
|
||
let enum_name = ast.ident; | ||
let variant_idents = enum_item.variants.into_iter().map(|v| v.ident); | ||
|
||
quote! { | ||
impl #enum_name { | ||
pub fn variants() -> &'static[Self] { | ||
&[ #(#enum_name::#variant_idents),* ] | ||
} | ||
pub fn iter_variants() -> impl Iterator<Item = &'static Self> { | ||
#enum_name::variants().iter() | ||
} | ||
} | ||
} | ||
.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use reqwest::StatusCode; | ||
|
||
use crate::data::command_data::Error; | ||
use crate::enums::emojis::{Emojis, GetId}; | ||
|
||
#[tokio::test] | ||
async fn test_valid_emoji_urls() -> Result<(), Error> { | ||
use reqwest::Client; | ||
|
||
let client = Client::new(); | ||
|
||
let make_discord_emoji_url = | ||
|emoji_id: &str| format!("https://cdn.discordapp.com/emojis/{}", emoji_id); | ||
|
||
for variant in Emojis::iter_variants() { | ||
let response = client | ||
.head(make_discord_emoji_url(variant.get_id())) | ||
.send() | ||
.await?; | ||
assert_eq!(response.status(), StatusCode::OK); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#![cfg(test)] | ||
|
||
#[cfg(feature = "network_test")] | ||
mod emojis; | ||
#[cfg(feature = "network_test")] | ||
mod urls; | ||
|
||
|