Skip to content

Commit 7ef5c8b

Browse files
marcianxcopybara-github
authored andcommitted
Add a new is_empty alternative to empty.
PiperOrigin-RevId: 775314573
1 parent 2879e51 commit 7ef5c8b

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

googletest/crate_docs.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ The following matchers are provided in GoogleTest Rust:
132132
| [`displays_as`] | A [`Display`] value whose formatted string is matched by the argument. |
133133
| [`each`] | A container all of whose elements the given argument matches. |
134134
| [`elements_are!`] | A container whose elements the arguments match, in order. |
135-
| [`empty`] | An empty collection. |
136135
| [`ends_with`] | A string ending with the given suffix. |
137136
| [`eq`] | A value equal to the argument, in the sense of the [`PartialEq`] trait. |
138137
| [`err`] | A [`Result`][std::result::Result] containing an `Err` variant the argument matches. |
@@ -141,9 +140,10 @@ The following matchers are provided in GoogleTest Rust:
141140
| [`gt`] | A [`PartialOrd`] value strictly greater than the given value. |
142141
| [`has_entry`] | A [`HashMap`] containing a given key whose value the argument matches. |
143142
| [`is_contained_in!`] | A container each of whose elements is matched by some given matcher. |
144-
| [`is_nan`] | A floating point number which is NaN. |
143+
| [`is_empty`] | An empty collection. |
145144
| [`is_finite`] | A floating point number which is neither infinite nor NaN. |
146145
| [`is_infinite`] | A floating point number which is positive or negative infinity. |
146+
| [`is_nan`] | A floating point number which is NaN. |
147147
| [`le`] | A [`PartialOrd`] value less than or equal to the given value. |
148148
| [`len`] | A container whose number of elements the argument matches. |
149149
| [`lt`] | A [`PartialOrd`] value strictly less than the given value. |
@@ -177,7 +177,6 @@ The following matchers are provided in GoogleTest Rust:
177177
[`derefs_to`]: matchers::derefs_to
178178
[`each`]: matchers::each
179179
[`elements_are!`]: matchers::elements_are
180-
[`empty`]: matchers::empty
181180
[`ends_with`]: matchers::ends_with
182181
[`eq`]: matchers::eq
183182
[`err`]: matchers::err
@@ -186,9 +185,10 @@ The following matchers are provided in GoogleTest Rust:
186185
[`gt`]: matchers::gt
187186
[`has_entry`]: matchers::has_entry
188187
[`is_contained_in!`]: matchers::is_contained_in
189-
[`is_nan`]: matchers::is_nan
188+
[`is_empty`]: matchers::is_empty
190189
[`is_finite`]: matchers::is_finite
191190
[`is_infinite`]: matchers::is_infinite
191+
[`is_nan`]: matchers::is_nan
192192
[`le`]: matchers::le
193193
[`len`]: matchers::len
194194
[`lt`]: matchers::lt

googletest/src/assertions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ pub mod internal {
16561656
/// # use googletest::prelude::*;
16571657
/// # fn would_not_compile_without_autoref() -> Result<()> {
16581658
/// let not_copyable = vec![1,2,3];
1659-
/// verify_that!(not_copyable, empty())?;
1659+
/// verify_that!(not_copyable, is_empty())?;
16601660
/// # Ok(())
16611661
/// # }
16621662
/// ```

googletest/src/matchers/empty_matcher.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ use std::fmt::Debug;
2929
/// # use std::collections::HashSet;
3030
/// # fn should_pass() -> Result<()> {
3131
/// let value: Vec<i32> = vec![];
32-
/// verify_that!(value, empty())?;
32+
/// verify_that!(value, is_empty())?;
3333
/// let value: HashSet<i32> = HashSet::new();
34-
/// verify_that!(value, empty())?;
34+
/// verify_that!(value, is_empty())?;
3535
/// let value: &[u32] = &[];
36-
/// verify_that!(value, empty())?;
36+
/// verify_that!(value, is_empty())?;
3737
/// # Ok(())
3838
/// # }
3939
/// # should_pass().unwrap();
4040
/// ```
41+
pub fn is_empty() -> EmptyMatcher {
42+
EmptyMatcher
43+
}
44+
45+
/// This is deprecated. Use `is_empty()` instead.
46+
#[deprecated(since = "0.14.1", note = "Use `is_empty()` instead.")]
4147
pub fn empty() -> EmptyMatcher {
4248
EmptyMatcher
4349
}
@@ -67,24 +73,24 @@ mod tests {
6773
#[test]
6874
fn empty_matcher_match_empty_vec() -> Result<()> {
6975
let value: Vec<i32> = vec![];
70-
verify_that!(value, empty())
76+
verify_that!(value, is_empty())
7177
}
7278

7379
#[test]
7480
fn empty_matcher_does_not_match_empty_vec() -> Result<()> {
7581
let value = vec![1, 2, 3];
76-
verify_that!(value, not(empty()))
82+
verify_that!(value, not(is_empty()))
7783
}
7884

7985
#[test]
8086
fn empty_matcher_matches_empty_slice() -> Result<()> {
8187
let value: &[i32] = &[];
82-
verify_that!(value, empty())
88+
verify_that!(value, is_empty())
8389
}
8490

8591
#[test]
8692
fn empty_matcher_matches_empty_hash_set() -> Result<()> {
8793
let value: HashSet<i32> = HashSet::new();
88-
verify_that!(value, empty())
94+
verify_that!(value, is_empty())
8995
}
9096
}

googletest/src/matchers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub use contains_regex_matcher::contains_regex;
7070
pub use derefs_to_matcher::derefs_to;
7171
pub use display_matcher::displays_as;
7272
pub use each_matcher::each;
73-
pub use empty_matcher::empty;
73+
pub use empty_matcher::{empty, is_empty};
7474
pub use eq_matcher::{eq, EqMatcher};
7575
pub use err_matcher::err;
7676
pub use ge_matcher::ge;

0 commit comments

Comments
 (0)