Skip to content

Commit 4def700

Browse files
committed
correct tests again
1 parent b4abb49 commit 4def700

File tree

12 files changed

+97
-59
lines changed

12 files changed

+97
-59
lines changed

meilisearch-index-setting-macro/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ fn get_index_config_implementation(
3939
struct_ident: &Ident,
4040
fields: &syn::Fields,
4141
) -> proc_macro2::TokenStream {
42-
let mut primary_key_attribute: String = "".to_string();
43-
let mut distinct_key_attribute: String = "".to_string();
44-
let mut displayed_attributes: Vec<String> = vec![];
45-
let mut searchable_attributes: Vec<String> = vec![];
46-
let mut filterable_attributes: Vec<String> = vec![];
47-
let mut sortable_attributes: Vec<String> = vec![];
42+
let mut primary_key_attribute = String::new();
43+
let mut distinct_key_attribute = String::new();
44+
let mut displayed_attributes = vec![];
45+
let mut searchable_attributes = vec![];
46+
let mut filterable_attributes = vec![];
47+
let mut sortable_attributes = vec![];
4848

4949
let index_name = struct_ident
5050
.to_string()
@@ -152,7 +152,7 @@ fn get_index_config_implementation(
152152
}
153153

154154
fn get_settings_token_for_list(
155-
field_name_list: &Vec<String>,
155+
field_name_list: &[String],
156156
method_name: &str,
157157
) -> proc_macro2::TokenStream {
158158
let string_attributes = field_name_list.iter().map(|attr| {
@@ -162,13 +162,13 @@ fn get_settings_token_for_list(
162162
});
163163
let method_ident = Ident::new(method_name, proc_macro2::Span::call_site());
164164

165-
if !field_name_list.is_empty() {
165+
if field_name_list.is_empty() {
166166
quote! {
167-
.#method_ident([#(#string_attributes),*])
167+
.#method_ident(::std::iter::empty::<&str>())
168168
}
169169
} else {
170170
quote! {
171-
.#method_ident(::std::iter::empty::<&str>())
171+
.#method_ident([#(#string_attributes),*])
172172
}
173173
}
174174
}
@@ -179,11 +179,11 @@ fn get_settings_token_for_string(
179179
) -> proc_macro2::TokenStream {
180180
let method_ident = Ident::new(method_name, proc_macro2::Span::call_site());
181181

182-
if !field_name.is_empty() {
182+
if field_name.is_empty() {
183+
proc_macro2::TokenStream::new()
184+
} else {
183185
quote! {
184186
.#method_ident(#field_name)
185187
}
186-
} else {
187-
proc_macro2::TokenStream::new()
188188
}
189189
}

meilisearch-test-macro/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
2020
if let (&mut Item::Fn(ref mut inner_fn), &mut Item::Fn(ref mut outer_fn)) =
2121
(&mut inner, &mut outer)
2222
{
23+
#[derive(Debug, PartialEq, Eq)]
24+
enum Param {
25+
Client,
26+
Index,
27+
String,
28+
}
29+
2330
inner_fn.sig.ident = Ident::new(
2431
&("_inner_meilisearch_test_macro_".to_string() + &inner_fn.sig.ident.to_string()),
2532
Span::call_site(),
@@ -32,36 +39,29 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
3239
"#[meilisearch_test] can only be applied to async functions"
3340
);
3441

35-
#[derive(Debug, PartialEq, Eq)]
36-
enum Param {
37-
Client,
38-
Index,
39-
String,
40-
}
41-
4242
let mut params = Vec::new();
4343

4444
let parameters = &inner_fn.sig.inputs;
45-
for param in parameters.iter() {
45+
for param in parameters {
4646
match param {
4747
FnArg::Typed(PatType { ty, .. }) => match &**ty {
48-
Type::Path(TypePath { path: Path { segments, .. }, .. } ) if segments.last().unwrap().ident.to_string() == "String" => {
48+
Type::Path(TypePath { path: Path { segments, .. }, .. } ) if segments.last().unwrap().ident == "String" => {
4949
params.push(Param::String);
5050
}
51-
Type::Path(TypePath { path: Path { segments, .. }, .. } ) if segments.last().unwrap().ident.to_string() == "Index" => {
51+
Type::Path(TypePath { path: Path { segments, .. }, .. } ) if segments.last().unwrap().ident == "Index" => {
5252
params.push(Param::Index);
5353
}
54-
Type::Path(TypePath { path: Path { segments, .. }, .. } ) if segments.last().unwrap().ident.to_string() == "Client" => {
54+
Type::Path(TypePath { path: Path { segments, .. }, .. } ) if segments.last().unwrap().ident == "Client" => {
5555
params.push(Param::Client);
5656
}
5757
// TODO: throw this error while pointing to the specific token
5858
ty => panic!(
59-
"#[meilisearch_test] can only receive Client, Index or String as parameters but received {:?}", ty
59+
"#[meilisearch_test] can only receive Client, Index or String as parameters but received {ty:?}"
6060
),
6161
},
6262
// TODO: throw this error while pointing to the specific token
6363
// Used `self` as a parameter
64-
_ => panic!(
64+
FnArg::Receiver(_) => panic!(
6565
"#[meilisearch_test] can only receive Client, Index or String as parameters"
6666
),
6767
}
@@ -168,7 +168,7 @@ pub fn meilisearch_test(params: TokenStream, input: TokenStream) -> TokenStream
168168
outer_block.push(parse_quote!(return result;));
169169

170170
outer_fn.sig.inputs.clear();
171-
outer_fn.sig.asyncness = inner_fn.sig.asyncness.clone();
171+
outer_fn.sig.asyncness = inner_fn.sig.asyncness;
172172
outer_fn.attrs.push(parse_quote!(#[tokio::test]));
173173
outer_fn.block.stmts = outer_block;
174174
} else {

src/client.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl Client {
116116
/// # movies.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
117117
/// # });
118118
/// ```
119+
#[must_use]
119120
pub fn multi_search(&self) -> MultiSearchQuery {
120121
MultiSearchQuery::new(self)
121122
}
@@ -131,6 +132,7 @@ impl Client {
131132
///
132133
/// assert_eq!(client.get_host(), "http://doggo.dog");
133134
/// ```
135+
#[must_use]
134136
pub fn get_host(&self) -> &str {
135137
&self.host
136138
}
@@ -146,6 +148,7 @@ impl Client {
146148
///
147149
/// assert_eq!(client.get_api_key(), Some("doggo"));
148150
/// ```
151+
#[must_use]
149152
pub fn get_api_key(&self) -> Option<&str> {
150153
self.api_key.as_deref()
151154
}
@@ -861,7 +864,7 @@ impl Client {
861864
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
862865
/// #
863866
/// # futures::executor::block_on(async move {
864-
/// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
867+
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
865868
/// # let index = client.create_index("movies_get_task", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap().try_make_index(&client).unwrap();
866869
/// let task = index.delete_all_documents().await.unwrap();
867870
///
@@ -890,8 +893,8 @@ impl Client {
890893
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
891894
/// #
892895
/// # futures::executor::block_on(async move {
893-
/// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
894-
/// let mut query = tasks::TasksSearchQuery::new(&client);
896+
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
897+
/// let mut query = TasksSearchQuery::new(&client);
895898
/// query.with_index_uids(["get_tasks_with"]);
896899
///
897900
/// let tasks = client.get_tasks_with(&query).await.unwrap();
@@ -923,8 +926,8 @@ impl Client {
923926
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
924927
/// #
925928
/// # futures::executor::block_on(async move {
926-
/// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
927-
/// let mut query = tasks::TasksCancelQuery::new(&client);
929+
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
930+
/// let mut query = TasksCancelQuery::new(&client);
928931
/// query.with_index_uids(["movies"]);
929932
///
930933
/// let res = client.cancel_tasks_with(&query).await.unwrap();
@@ -959,8 +962,8 @@ impl Client {
959962
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
960963
/// #
961964
/// # futures::executor::block_on(async move {
962-
/// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
963-
/// let mut query = tasks::TasksDeleteQuery::new(&client);
965+
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
966+
/// let mut query = TasksDeleteQuery::new(&client);
964967
/// query.with_index_uids(["movies"]);
965968
///
966969
/// let res = client.delete_tasks_with(&query).await.unwrap();
@@ -992,7 +995,7 @@ impl Client {
992995
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
993996
/// #
994997
/// # futures::executor::block_on(async move {
995-
/// # let client = client::Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
998+
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
996999
/// let tasks = client.get_tasks().await.unwrap();
9971000
///
9981001
/// assert!(tasks.results.len() > 0);
@@ -1160,7 +1163,7 @@ mod tests {
11601163
let mut s = mockito::Server::new_async().await;
11611164
let mock_server_url = s.url();
11621165
let path = "/hello";
1163-
let address = &format!("{}{}", mock_server_url, path);
1166+
let address = &format!("{mock_server_url}{path}");
11641167
let user_agent = &*qualified_version();
11651168

11661169
let assertions = vec![

src/documents.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use crate::{Client, Error, Index, Settings, Task};
5151
pub trait IndexConfig {
5252
const INDEX_STR: &'static str;
5353

54+
#[must_use]
5455
fn index(client: &Client) -> Index {
5556
client.index(Self::INDEX_STR)
5657
}
@@ -77,6 +78,7 @@ pub struct DocumentQuery<'a> {
7778
}
7879

7980
impl<'a> DocumentQuery<'a> {
81+
#[must_use]
8082
pub fn new(index: &Index) -> DocumentQuery {
8183
DocumentQuery {
8284
index,
@@ -190,6 +192,7 @@ pub struct DocumentsQuery<'a> {
190192
}
191193

192194
impl<'a> DocumentsQuery<'a> {
195+
#[must_use]
193196
pub fn new(index: &Index) -> DocumentsQuery {
194197
DocumentsQuery {
195198
index,
@@ -321,6 +324,7 @@ pub struct DocumentDeletionQuery<'a> {
321324
}
322325

323326
impl<'a> DocumentDeletionQuery<'a> {
327+
#[must_use]
324328
pub fn new(index: &Index) -> DocumentDeletionQuery {
325329
DocumentDeletionQuery {
326330
index,
@@ -527,7 +531,7 @@ mod tests {
527531
#[meilisearch_test]
528532
async fn test_get_documents_with_error_hint() -> Result<(), Error> {
529533
let meilisearch_url = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
530-
let client = Client::new(format!("{}/hello", meilisearch_url), Some("masterKey"));
534+
let client = Client::new(format!("{meilisearch_url}/hello"), Some("masterKey"));
531535
let index = client.index("test_get_documents_with_filter_wrong_ms_version");
532536

533537
let documents = DocumentsQuery::new(&index)
@@ -552,7 +556,7 @@ mod tests {
552556
}
553557
_ => panic!("The error was expected to be a MeilisearchCommunicationError error, but it was not."),
554558
};
555-
assert_eq!(format!("{}", error), displayed_error);
559+
assert_eq!(format!("{error}"), displayed_error);
556560

557561
Ok(())
558562
}
@@ -583,7 +587,7 @@ Hint: It might not be working because you're not up to date with the Meilisearch
583587
}
584588
_ => panic!("The error was expected to be a MeilisearchCommunicationError error, but it was not."),
585589
};
586-
assert_eq!(format!("{}", error), displayed_error);
590+
assert_eq!(format!("{error}"), displayed_error);
587591

588592
Ok(())
589593
}

src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl std::fmt::Display for MeilisearchCommunicationError {
8484
self.status_code
8585
)?;
8686
if let Some(message) = &self.message {
87-
write!(f, " {}", message)?;
87+
write!(f, " {message}")?;
8888
}
8989
write!(f, "\nurl: {}", self.url)?;
9090
Ok(())

src/features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct ExperimentalFeatures<'a> {
3838
}
3939

4040
impl<'a> ExperimentalFeatures<'a> {
41+
#[must_use]
4142
pub fn new(client: &'a Client) -> Self {
4243
ExperimentalFeatures {
4344
client,

0 commit comments

Comments
 (0)