asserting/
assertions.rs

1//! Definitions of the assertions that are provided by this crate.
2//!
3//! Assertions define the methods that are used to assert that the actual test
4//! result is as expected. Assertions are defined by traits that are implemented
5//! for one or several types. An assertion can be applied to all types that
6//! implement this assertion.
7//!
8//! All assertions provided by this crate are defined in this module. Browse
9//! over the traits in this module to get information about all provided
10//! assertions.
11#![allow(clippy::wrong_self_convention, clippy::return_self_not_must_use)]
12
13use crate::spec::Spec;
14use crate::std::fmt::Debug;
15use crate::std::ops::RangeBounds;
16use crate::std::string::String;
17
18/// Assert whether two values are equal or not.
19///
20/// These assertions are implemented for all types that implement `PartialEq<E>`
21/// with `E` being the type of the expected value.
22///
23/// # Examples
24///
25/// ```
26/// use asserting::prelude::*;
27///
28/// let subject = "ea rebum dignissim suscipit".to_string();
29/// assert_that!(subject).is_equal_to("ea rebum dignissim suscipit");
30///
31/// let the_answer = 42;
32/// assert_that!(the_answer).is_equal_to(42);
33/// ```
34pub trait AssertEquality<E> {
35    /// Verifies that the subject is equal to some other value.
36    ///
37    /// # Examples
38    ///
39    /// ```
40    /// use asserting::prelude::*;
41    ///
42    /// let the_answer = 42;
43    /// assert_that!(the_answer).is_equal_to(42);
44    ///
45    /// assert_that!(6 * 7).is_equal_to(42);
46    ///
47    /// let subject = "volutpat sunt te tincidunt".to_string();
48    /// assert_that!(subject).is_equal_to("volutpat sunt te tincidunt");
49    /// ```
50    #[track_caller]
51    fn is_equal_to(self, expected: E) -> Self;
52
53    /// Verifies that subject is not equal to some other value.
54    ///
55    /// # Examples
56    ///
57    /// ```
58    /// use asserting::prelude::*;
59    ///
60    /// assert_that!(5 * 8).is_not_equal_to(42);
61    ///
62    /// let subject = "volutpat sunt te tincidunt".to_string();
63    /// assert_that!(subject).is_not_equal_to("Hello, World!");
64    /// ```
65    #[track_caller]
66    fn is_not_equal_to(self, expected: E) -> Self;
67}
68
69/// Assert approximate equality for floating point numbers.
70///
71/// # Examples
72///
73/// ```
74/// use asserting::prelude::*;
75///
76/// assert_that!(10.0_f32 / 3.0).is_close_to_with_margin(3.333, (0.001, 5));
77/// assert_that!(10.0_f64 / 3.0).is_close_to_with_margin(3.333, (0.001, 5));
78///
79/// assert_that!(10.0_f32 / 3.0).is_not_close_to_with_margin(3.333, (0.0001, 5));
80/// assert_that!(10.0_f64 / 3.0).is_not_close_to_with_margin(3.333, (0.0001, 5));
81/// ```
82#[cfg(feature = "float-cmp")]
83#[cfg_attr(docsrs, doc(cfg(feature = "float-cmp")))]
84pub trait AssertIsCloseToWithinMargin<E, M> {
85    /// Verifies that the actual value is approximately equal to the expected
86    /// value.
87    ///
88    /// For comparison, the epsilon and ULPS values of the given margin are
89    /// used.
90    ///
91    /// # Examples
92    ///
93    /// ```
94    /// use asserting::prelude::*;
95    ///
96    /// assert_that!(10.0_f32 / 3.0).is_close_to_with_margin(3.333, (0.001, 5));
97    /// assert_that!(10.0_f64 / 3.0).is_close_to_with_margin(3.333, (0.001, 5));
98    /// ```
99    ///
100    /// The following articles describe the challenges with comparing floating
101    /// point numbers and the meaning of the epsilon and ULPS values:
102    ///
103    /// * [https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)
104    /// * [https://floating-point-gui.de/errors/comparison/](https://floating-point-gui.de/errors/comparison/)
105    #[track_caller]
106    fn is_close_to_with_margin(self, expected: E, margin: impl Into<M>) -> Self;
107
108    /// Verifies that the actual value not approximately equals to the expected
109    /// value.
110    ///
111    /// For comparison, the epsilon and ULPS values of the given margin are
112    /// used.
113    ///
114    /// # Examples
115    ///
116    /// ```
117    /// use asserting::prelude::*;
118    ///
119    /// assert_that!(10.0_f32 / 3.0).is_not_close_to_with_margin(3.333, (0.0001, 5));
120    /// assert_that!(10.0_f64 / 3.0).is_not_close_to_with_margin(3.333, (0.0001, 5));
121    /// ```
122    ///
123    /// The following articles describe the challenges with comparing floating
124    /// point numbers and the meaning of the epsilon and ULPS values:
125    ///
126    /// * [https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)
127    /// * [https://floating-point-gui.de/errors/comparison/](https://floating-point-gui.de/errors/comparison/)
128    #[track_caller]
129    fn is_not_close_to_with_margin(self, expected: E, margin: impl Into<M>) -> Self;
130}
131
132/// Assert approximate equality for floating point numbers.
133///
134/// # Examples
135///
136/// ```
137/// use asserting::prelude::*;
138///
139/// assert_that!(5.0_f32 / 2.0).is_close_to(2.5);
140/// assert_that!(10.0_f64 / 8.0).is_close_to(1.25);
141///
142/// assert_that!(5.0_f32 / 2.5).is_not_close_to(2.01);
143/// assert_that!(10.0_f64 / 8.0).is_not_close_to(1.255);
144/// ```
145#[cfg(feature = "float-cmp")]
146#[cfg_attr(docsrs, doc(cfg(feature = "float-cmp")))]
147pub trait AssertIsCloseToWithDefaultMargin<E> {
148    /// Verifies that the actual value is approximately equal to the expected
149    /// value.
150    ///
151    /// For the approximation, a default margin with 4 * epsilon and 4 * ULPS is
152    /// used.
153    ///
154    /// # Examples
155    ///
156    /// ```
157    /// use asserting::prelude::*;
158    ///
159    /// assert_that!(5.0_f32 / 2.0).is_close_to(2.5);
160    /// assert_that!(10.0_f64 / 8.0).is_close_to(1.25);
161    /// ```
162    ///
163    /// The following articles describe the challenges with comparing floating
164    /// point numbers and the meaning of the epsilon and ULPS values:
165    ///
166    /// * [https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)
167    /// * [https://floating-point-gui.de/errors/comparison/](https://floating-point-gui.de/errors/comparison/)
168    #[track_caller]
169    fn is_close_to(self, expected: E) -> Self;
170
171    /// Verifies that the actual value is not approximately equal to the expected
172    /// value.
173    ///
174    /// For the approximation, a default margin with 4 * epsilon and 4 * ULPS is
175    /// used.
176    ///
177    /// # Examples
178    ///
179    /// ```
180    /// use asserting::prelude::*;
181    ///
182    /// assert_that!(10.0_f32 / 2.0).is_not_close_to(5.01);
183    /// assert_that!(10.0_f64 / 2.0).is_not_close_to(5.01);
184    /// ```
185    ///
186    /// The following articles describe the challenges with comparing floating
187    /// point numbers and the meaning of the epsilon and ULPS values:
188    ///
189    /// * [https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)
190    /// * [https://floating-point-gui.de/errors/comparison/](https://floating-point-gui.de/errors/comparison/)
191    #[track_caller]
192    fn is_not_close_to(self, expected: E) -> Self;
193}
194
195/// Assert whether a value is greater than or less than another value, as well
196/// as at most as big or at least as big as another value.
197///
198/// These assertions are implemented for all types that implement
199/// `PartialOrd<E>` with `E` being the type of the expected value the subject
200/// is being compared to.
201///
202/// # Examples
203///
204/// ```
205/// use time::macros::date;
206/// use asserting::prelude::*;
207///
208/// let some_result: u16 = 42;
209///
210/// assert_that!(some_result).is_at_most(43);
211/// assert_that!(some_result).is_at_most(42);
212/// assert_that!(some_result).is_at_least(42);
213/// assert_that!(some_result).is_at_least(41);
214/// assert_that!(some_result).is_greater_than(41);
215/// assert_that!(some_result).is_less_than(43);
216///
217/// let some_letter: char = 'M';
218///
219/// assert_that!(some_letter).is_before('P');
220/// assert_that!(some_letter).is_after('K');
221/// assert_that!(some_letter).is_between('A', 'Z');
222///
223/// let some_date = date!(2025-04-20);
224///
225/// assert_that!(some_date).is_before(date!(2025-04-21));
226/// assert_that!(some_date).is_after(date!(2025-04-19));
227/// assert_that!(some_date).is_between(date!(2025-04-19), date!(2025-04-21));
228///```
229pub trait AssertOrder<E> {
230    /// Verifies that the subject is less than some expected value.
231    ///
232    /// # Examples
233    ///
234    /// ```
235    /// use asserting::prelude::*;
236    ///
237    /// assert_that!(4).is_less_than(5);
238    /// assert_that!(-1).is_less_than(1);
239    /// assert_that!(-2).is_less_than(-1);
240    /// assert_that!(0.5).is_less_than(1.0);
241    /// ```
242    #[track_caller]
243    fn is_less_than(self, expected: E) -> Self;
244
245    /// Verifies that the subject is greater than some expected value.
246    ///
247    /// # Examples
248    ///
249    /// ```
250    /// use asserting::prelude::*;
251    ///
252    /// assert_that!(5).is_greater_than(4);
253    /// assert_that!(1).is_greater_than(-1);
254    /// assert_that!(-1).is_greater_than(-2);
255    /// assert_that!(0.5).is_greater_than(0.1);
256    /// ```
257    #[track_caller]
258    fn is_greater_than(self, expected: E) -> Self;
259
260    /// Verifies that the subject is less than or equal to some expected value.
261    ///
262    /// # Examples
263    ///
264    /// ```
265    /// use asserting::prelude::*;
266    ///
267    /// assert_that!(4).is_at_most(5);
268    /// assert_that!(5).is_at_most(5);
269    /// assert_that!(-2).is_at_most(-1);
270    /// assert_that!(-2).is_at_most(-2);
271    /// assert_that!(0.9).is_at_most(1.0);
272    /// ```
273    #[track_caller]
274    fn is_at_most(self, expected: E) -> Self;
275
276    /// Verifies that the subject is greater than or equal to some expected
277    /// value.
278    ///
279    /// # Examples
280    ///
281    /// ```
282    /// use asserting::prelude::*;
283    ///
284    /// assert_that!(5).is_at_least(4);
285    /// assert_that!(5).is_at_least(5);
286    /// assert_that!(-1).is_at_least(-2);
287    /// assert_that!(-2).is_at_least(-2);
288    /// assert_that!(1.4).is_at_least(1.0);
289    /// ```
290    #[track_caller]
291    fn is_at_least(self, expected: E) -> Self;
292
293    /// Verifies that the subject is before some expected value.
294    ///
295    /// This is equivalent to asserting a subject to be less than the expected
296    /// value.
297    ///
298    /// # Examples
299    ///
300    /// ```
301    /// use asserting::prelude::*;
302    ///
303    /// assert_that!('M').is_before('N');
304    /// assert_that!(4).is_before(5);
305    /// assert_that!(0.8).is_before(1.0);
306    ///
307    /// use time::macros::date;
308    ///
309    /// assert_that!(date!(2025-05-30)).is_before(date!(2025-06-01));
310    /// ```
311    #[track_caller]
312    fn is_before(self, expected: E) -> Self;
313
314    /// Verifies that the subject is after some expected value.
315    ///
316    /// This is equivalent to asserting a subject to be greater than the
317    /// expected value.
318    ///
319    /// # Examples
320    ///
321    /// ```
322    /// use asserting::prelude::*;
323    ///
324    /// assert_that!('N').is_after('M');
325    /// assert_that!(5).is_after(4);
326    /// assert_that!(1.2).is_after(1.0);
327    ///
328    /// use time::macros::date;
329    ///
330    /// assert_that!(date!(2025-06-01)).is_after(date!(2025-05-30));
331    /// ```
332    #[track_caller]
333    fn is_after(self, expected: E) -> Self;
334
335    /// Verifies that the subject is between a min value and a max value.
336    ///
337    /// Min and max values are included. This is equivalent to asserting a
338    /// subject to be greater than or equal to the min value and to be less than
339    /// or equal to the max value.
340    ///
341    /// # Examples
342    ///
343    /// ```
344    /// use asserting::prelude::*;
345    ///
346    /// assert_that!('B').is_between('A', 'C');
347    /// assert_that!(5).is_between(4, 6);
348    /// assert_that!(1.5).is_between(0.9, 1.8);
349    ///
350    /// use time::macros::date;
351    ///
352    /// assert_that!(date!(2025-06-01)).is_between(date!(2025-05-30), date!(2025-06-02));
353    /// ```
354    #[track_caller]
355    fn is_between(self, min: E, max: E) -> Self;
356}
357
358/// Assert whether a value is within an expected range.
359///
360/// The expected range can be any of range.
361///
362/// These assertions are implemented for all types `T` that implement
363/// `PartialOrd<E>` with `E` being the type of the expected value. And `E` must
364/// implement `PartialOrd<T>`.
365///
366/// # Examples
367///
368/// ```
369/// use asserting::prelude::*;
370///
371/// assert_that!(7).is_in_range(6..8);
372/// assert_that!(8).is_not_in_range(6..8);
373/// assert_that!(1234).is_in_range(6..);
374/// assert_that!(5).is_not_in_range(6..);
375/// assert_that!(-33).is_in_range(..-1);
376///
377/// assert_that!('M').is_in_range('A'..='Z');
378/// assert_that!('M').is_not_in_range('a'..='z');
379/// assert_that!('k').is_in_range('h'..'n');
380/// assert_that!('r').is_in_range('H'..);
381/// assert_that!('N').is_in_range(..'n');
382/// ```
383pub trait AssertInRange<E> {
384    /// Verifies that the subject is within the expected range.
385    ///
386    /// # Examples
387    ///
388    /// ```
389    /// use asserting::prelude::*;
390    ///
391    /// assert_that!(7).is_in_range(6..8);
392    /// assert_that!(7).is_in_range(7..8);
393    /// assert_that!(7).is_in_range(6..=7);
394    /// assert_that!(123).is_in_range(10..);
395    /// assert_that!(-33).is_in_range(..-10);
396    ///
397    /// assert_that!(0.5).is_in_range(0.0..1.0);
398    ///
399    /// assert_that!('K').is_in_range('A'..'M');
400    /// assert_that!('g').is_in_range('a'..='z');
401    /// assert_that!('!').is_in_range(..'A');
402    /// assert_that!('~').is_in_range('z'..);
403    /// ```
404    #[track_caller]
405    fn is_in_range<R>(self, range: R) -> Self
406    where
407        R: RangeBounds<E> + Debug;
408
409    /// Verifies that the subject is not within the expected range.
410    ///
411    /// # Examples
412    ///
413    /// ```
414    /// use asserting::prelude::*;
415    ///
416    /// assert_that!(10).is_not_in_range(1..10);
417    /// assert_that!(10).is_not_in_range(1..=9);
418    ///
419    /// assert_that!(1.0).is_not_in_range(0.0..1.0);
420    ///
421    /// assert_that!('C').is_not_in_range('A'..'C');
422    /// assert_that!('D').is_not_in_range('A'..='C');
423    /// assert_that!('b').is_not_in_range('A'..='Z');
424    /// ```
425    #[track_caller]
426    fn is_not_in_range<R>(self, range: R) -> Self
427    where
428        R: RangeBounds<E> + Debug;
429}
430
431/// Assert whether a numeric value is negative or positive.
432///
433/// # Examples
434///
435/// ```
436/// use asserting::prelude::*;
437///
438/// assert_that!(-42).is_negative();
439/// assert_that!(42).is_positive();
440/// assert_that!(0).is_not_negative();
441/// assert_that!(1).is_not_negative();
442/// assert_that!(0).is_not_positive();
443/// assert_that!(-1).is_not_positive();
444///
445/// assert_that!(-0.1).is_negative();
446/// assert_that!(0.1).is_positive();
447/// assert_that!(0.0).is_not_negative();
448/// assert_that!(0.1).is_not_negative();
449/// assert_that!(0.0).is_not_positive();
450/// assert_that!(-0.1).is_not_positive();
451/// ```
452pub trait AssertSignum {
453    /// Verifies that the subject is a negative number.
454    ///
455    /// This is equivalent to asserting that a number is less than 0.
456    ///
457    /// # Examples
458    ///
459    /// ```
460    /// use asserting::prelude::*;
461    ///
462    /// assert_that!(-5).is_negative();
463    /// assert_that!(-0.9).is_negative();
464    /// ```
465    ///
466    /// ```should_panic
467    /// use asserting::prelude::*;
468    ///
469    /// assert_that!(0).is_negative();
470    /// ```
471    #[track_caller]
472    fn is_negative(self) -> Self;
473
474    /// Verifies that the subject is a non-negative number.
475    ///
476    /// This is equivalent to asserting that a number is greater than or equal
477    /// to 0.
478    ///
479    /// # Examples
480    ///
481    /// ```
482    /// use asserting::prelude::*;
483    ///
484    /// assert_that!(5).is_not_negative();
485    /// assert_that!(1.3).is_not_negative();
486    /// assert_that!(0).is_not_negative();
487    /// ```
488    #[track_caller]
489    fn is_not_negative(self) -> Self;
490
491    /// Verifies that the subject is a positive number.
492    ///
493    /// This is equivalent to asserting that a number is greater than 0.
494    ///
495    /// # Examples
496    ///
497    /// ```
498    /// use asserting::prelude::*;
499    ///
500    /// assert_that!(5).is_positive();
501    /// assert_that!(2.7).is_positive();
502    /// ```
503    ///
504    /// ```should_panic
505    /// use asserting::prelude::*;
506    ///
507    /// assert_that!(0).is_positive();
508    /// ```
509    #[track_caller]
510    fn is_positive(self) -> Self;
511
512    /// Verifies that the subject is a non-positive number.
513    ///
514    /// This is equivalent to asserting that a number is less than or equal to
515    /// 0.
516    ///
517    /// # Examples
518    ///
519    /// ```
520    /// use asserting::prelude::*;
521    ///
522    /// assert_that!(-5).is_not_positive();
523    /// assert_that!(-0.9).is_not_positive();
524    /// assert_that!(0).is_not_positive();
525    /// ```
526    #[track_caller]
527    fn is_not_positive(self) -> Self;
528}
529
530/// Assert the additive and multiplicative identity of a number.
531///
532/// # Examples
533///
534/// ```
535/// use asserting::prelude::*;
536///
537/// assert_that!(0).is_zero();
538/// assert_that!(1).is_one();
539/// assert_that!(0.0).is_zero();
540/// assert_that!(1.0).is_one();
541/// ```
542pub trait AssertNumericIdentity {
543    /// Verifies whether the subject is the additive identity (zero).
544    ///
545    /// # Examples
546    ///
547    /// ```
548    /// use asserting::prelude::*;
549    ///
550    /// assert_that!(0).is_zero();
551    /// assert_that!(0.0).is_zero();
552    /// ```
553    #[track_caller]
554    fn is_zero(self) -> Self;
555
556    /// Verifies whether the subject is the multiplicative identity (one).
557    ///
558    /// # Examples
559    ///
560    /// ```
561    /// use asserting::prelude::*;
562    ///
563    /// assert_that!(1).is_one();
564    /// assert_that!(1.0).is_one();
565    #[track_caller]
566    fn is_one(self) -> Self;
567}
568
569/// Assert whether a numeric value is infinite or finite.
570///
571/// # Examples
572///
573/// ```
574/// use asserting::prelude::*;
575///
576/// assert_that!(0.1).is_finite();
577/// assert_that!(0.0).is_finite();
578/// assert_that!(f32::INFINITY).is_infinite();
579/// assert_that!(f32::NEG_INFINITY).is_infinite();
580/// assert_that!(f64::INFINITY).is_infinite();
581/// assert_that!(f64::NEG_INFINITY).is_infinite();
582/// ```
583///
584/// Assert negative and positive infinity:
585///
586/// ```
587/// use asserting::prelude::*;
588///
589/// assert_that!(f64::INFINITY).is_positive().is_infinite();
590/// assert_that!(f64::NEG_INFINITY).is_negative().is_infinite();
591/// ```
592pub trait AssertInfinity {
593    /// Verifies that the subject is an infinite number.
594    ///
595    /// # Examples
596    ///
597    /// ```
598    /// use asserting::prelude::*;
599    ///
600    /// assert_that!(f32::INFINITY).is_infinite();
601    /// assert_that!(f64::INFINITY).is_infinite();
602    ///
603    /// assert_that!(f32::INFINITY).is_positive().is_infinite();
604    /// assert_that!(f32::NEG_INFINITY).is_negative().is_infinite();
605    ///
606    /// assert_that!(f64::INFINITY).is_positive().is_infinite();
607    /// assert_that!(f64::NEG_INFINITY).is_negative().is_infinite();
608    /// ```
609    #[track_caller]
610    fn is_infinite(self) -> Self;
611
612    /// Verifies that the subject is a finite number.
613    ///
614    /// # Examples
615    ///
616    /// ```
617    /// use asserting::prelude::*;
618    ///
619    /// assert_that!(2.96).is_finite();
620    /// assert_that!(0.0).is_finite();
621    /// assert_that!(-123.45).is_finite();
622    /// ```
623    #[track_caller]
624    fn is_finite(self) -> Self;
625}
626
627/// Assert whether a numeric value is not a number.
628///
629/// # Examples
630///
631/// ```
632/// use asserting::prelude::*;
633///
634/// assert_that!(0.1).is_a_number();
635/// assert_that!(0.0).is_a_number();
636/// assert_that!(f32::NAN).is_not_a_number();
637/// assert_that!(f64::NAN).is_not_a_number();
638/// ```
639pub trait AssertNotANumber {
640    /// Verifies that the subject is not a number.
641    ///
642    /// # Examples
643    ///
644    /// ```
645    /// use asserting::prelude::*;
646    ///
647    /// assert_that!(f32::NAN).is_not_a_number();
648    /// assert_that!(f64::NAN).is_not_a_number();
649    /// ```
650    #[track_caller]
651    fn is_not_a_number(self) -> Self;
652
653    /// Verifies that the subject is a number.
654    ///
655    /// # Examples
656    ///
657    /// ```
658    /// use asserting::prelude::*;
659    ///
660    /// assert_that!(0.1).is_a_number();
661    /// assert_that!(0.0).is_a_number();
662    /// assert_that!(-0.1).is_a_number();
663    /// ```
664    #[track_caller]
665    fn is_a_number(self) -> Self;
666}
667
668/// Assert whether some value or expression is true or false.
669///
670/// # Examples
671///
672/// ```
673/// use asserting::prelude::*;
674///
675/// let subject = 42 > 41;
676/// assert_that!(subject).is_true();
677///
678/// assert_that!(12 == 12).is_true();
679///
680/// assert_that!(42 < 42).is_false();
681/// ```
682pub trait AssertBoolean {
683    /// Verifies that the subject is true.
684    ///
685    /// # Examples
686    ///
687    /// ```
688    /// use asserting::prelude::*;
689    ///
690    /// let subject = 42 > 41;
691    /// assert_that!(subject).is_true();
692    ///
693    /// assert_that!(12 == 12).is_true();
694    ///
695    /// assert_that!(41 < 42).is_true();
696    /// ```
697    #[track_caller]
698    fn is_true(self) -> Self;
699
700    /// Verifies that the subject is false.
701    ///
702    /// # Examples
703    ///
704    /// ```
705    /// use asserting::prelude::*;
706    ///
707    /// let subject = 42 > 43;
708    /// assert_that!(subject).is_false();
709    ///
710    /// assert_that!(12 == 13).is_false();
711    ///
712    /// assert_that!(42 < 42).is_false();
713    /// ```
714    #[track_caller]
715    fn is_false(self) -> Self;
716}
717
718/// Assert whether a string, collection or iterator is empty or not.
719///
720/// These assertions are implemented for all types `T` that implement the
721/// trait [`IsEmptyProperty`](crate::properties::IsEmptyProperty). This
722/// property trait is implemented for string like types and collection like
723/// types of the `std` lib. For example:
724///
725/// * `String`, `&str`, `OsString`, `CString`, etc.
726/// * `Vec`, array, slice, `VecDeque`, `LinkedList`, etc.
727/// * `HashMap`, `HashSet`, `BTreeSet`, etc.
728///
729/// # Examples
730///
731/// ```
732/// use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
733/// use asserting::prelude::*;
734///
735/// let some_string = String::new();
736/// assert_that!(some_string).is_empty();
737///
738/// let some_str = "ad praesent aliqua qui";
739/// assert_that!(some_str).is_not_empty();
740///
741/// let some_vec: Vec<String> = vec![];
742/// assert_that!(some_vec).is_empty();
743///
744/// let some_array = [12, 24, 36, 48];
745/// assert_that!(some_array).is_not_empty();
746///
747/// let some_slice: &[_] = &['a', 'b', 'c'][..];
748/// assert_that!(some_slice).is_not_empty();
749///
750/// let some_btree_set = BTreeSet::<i64>::new();
751/// assert_that!(&some_btree_set).is_empty();
752///
753/// let some_dequeue = VecDeque::<String>::new();
754/// assert_that!(some_dequeue).is_empty();
755/// ```
756///
757/// with crate feature `std` enabled:
758///
759/// ```
760/// # #[cfg(not(feature = "std"))]
761/// # fn main() {
762/// # }
763/// # #[cfg(feature = "std")]
764/// # fn main() {
765/// use std::collections::{HashMap, HashSet};
766/// use asserting::prelude::*;
767///
768/// let some_set: HashSet<_> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
769/// assert_that!(&some_set).is_not_empty();
770///
771/// let some_map: HashMap<String, usize> = HashMap::new();
772/// assert_that!(some_map).is_empty();
773/// # }
774/// ```
775pub trait AssertEmptiness {
776    /// Verifies that the subject is empty.
777    ///
778    /// # Examples
779    ///
780    /// ```
781    /// use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
782    /// use asserting::prelude::*;
783    ///
784    /// let some_string = String::new();
785    /// assert_that!(some_string).is_empty();
786    ///
787    /// let some_vec: Vec<String> = vec![];
788    /// assert_that!(some_vec).is_empty();
789    ///
790    /// let some_array: [char; 0] = [];
791    /// assert_that!(some_array).is_empty();
792    ///
793    /// let some_slice: &[char] = &[][..];
794    /// assert_that!(some_slice).is_empty();
795    ///
796    /// let some_btree_set = BTreeSet::<i64>::new();
797    /// assert_that!(&some_btree_set).is_empty();
798    ///
799    /// let some_dequeue = VecDeque::<String>::new();
800    /// assert_that!(some_dequeue).is_empty();
801    /// ```
802    #[track_caller]
803    fn is_empty(self) -> Self;
804
805    /// Verifies that the subject is not empty.
806    ///
807    /// # Examples
808    ///
809    /// ```
810    /// use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
811    /// use asserting::prelude::*;
812    ///
813    /// let some_str = "ad praesent aliqua qui";
814    /// assert_that!(some_str).is_not_empty();
815    ///
816    /// let some_vec = vec![1, 2, 3];
817    /// assert_that!(some_vec).is_not_empty();
818    ///
819    /// let some_array = [12, 24, 36, 48];
820    /// assert_that!(some_array).is_not_empty();
821    ///
822    /// let some_slice: &[_] = &['a', 'b', 'c'][..];
823    /// assert_that!(some_slice).is_not_empty();
824    /// ```
825    #[track_caller]
826    fn is_not_empty(self) -> Self;
827}
828
829/// Assert the length of a subject.
830///
831/// These assertions are implemented for all types `T` that implement the
832/// trait [`LengthProperty`](crate::properties::LengthProperty). This
833/// property trait is implemented for string like types and collection like
834/// types of the `std` lib. For example:
835///
836/// * `String`, `&str`, `OsString`, `OsStr`
837/// * `Vec`, array, slice, `VecDeque`, `LinkedList`, etc.
838/// * `HashMap`, `HashSet`, `BTreeSet`, etc.
839///
840/// # Examples
841///
842/// ```
843/// use std::collections::{BTreeSet, VecDeque};
844/// use asserting::prelude::*;
845///
846/// let some_str = "takimata te iriure nonummy";
847/// assert_that!(some_str).has_length(26);
848/// assert_that!(some_str).has_length_in_range(12..32);
849/// assert_that!(some_str).has_length_in_range(12..=32);
850/// assert_that!(some_str).has_length_in_range(12..);
851/// assert_that!(some_str).has_length_in_range(..32);
852/// assert_that!(some_str).has_length_in_range(..=32);
853/// assert_that!(some_str).has_length_less_than(27);
854/// assert_that!(some_str).has_length_greater_than(25);
855/// assert_that!(some_str).has_at_most_length(26);
856/// assert_that!(some_str).has_at_most_length(30);
857/// assert_that!(some_str).has_at_least_length(26);
858/// assert_that!(some_str).has_at_least_length(20);
859///
860/// let some_vec = vec!['m', 'Q', 'k', 'b'];
861/// assert_that!(&some_vec).has_length(4);
862/// assert_that!(&some_vec).has_length_in_range(2..6);
863/// assert_that!(&some_vec).has_length_in_range(2..=6);
864/// assert_that!(&some_vec).has_length_in_range(2..);
865/// assert_that!(&some_vec).has_length_in_range(..6);
866/// assert_that!(&some_vec).has_length_in_range(..=6);
867/// assert_that!(&some_vec).has_length_less_than(5);
868/// assert_that!(&some_vec).has_length_greater_than(3);
869/// assert_that!(&some_vec).has_at_most_length(4);
870/// assert_that!(&some_vec).has_at_most_length(10);
871/// assert_that!(&some_vec).has_at_least_length(4);
872/// assert_that!(&some_vec).has_at_least_length(1);
873///
874/// let some_btree_set = BTreeSet::from_iter([1, 3, 5, 7, 11, 13, 17, 19]);
875/// assert_that!(some_btree_set).has_length(8);
876///
877/// let some_dequeue = VecDeque::from_iter(["one", "two", "three"]);
878/// assert_that!(&some_dequeue).has_length(3);
879/// ```
880///
881/// with crate feature `std` enabled:
882///
883/// ```
884/// # #[cfg(not(feature = "std"))]
885/// # fn main() {
886/// # }
887/// # #[cfg(feature = "std")]
888/// # fn main() {
889/// use std::collections::{HashMap, HashSet};
890/// use asserting::prelude::*;
891///
892/// let some_set: HashSet<u8> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
893/// assert_that!(some_set).has_length(8);
894///
895/// let some_map: HashMap<char, usize> = [('A', 25), ('B', 2), ('C', 12), ('D', 18)].into_iter().collect();
896/// assert_that!(&some_map).has_length(4);
897/// # }
898/// ```
899pub trait AssertHasLength<E> {
900    /// Verifies that the subject has the expected length.
901    ///
902    /// # Examples
903    ///
904    /// ```
905    /// use std::collections::{BTreeSet, VecDeque};
906    /// use asserting::prelude::*;
907    ///
908    /// let some_str = "takimata te iriure nonummy";
909    /// assert_that!(some_str).has_length(26);
910    ///
911    /// let some_vec = vec!['m', 'Q', 'k', 'b'];
912    /// assert_that!(&some_vec).has_length(4);
913    ///
914    /// let some_btree_set = BTreeSet::from_iter([1, 3, 5, 7, 11, 13, 17, 19]);
915    /// assert_that!(some_btree_set).has_length(8);
916    ///
917    /// let some_dequeue = VecDeque::from_iter(["one", "two", "three"]);
918    /// assert_that!(&some_dequeue).has_length(3);
919    /// ```
920    ///
921    /// with crate feature `std` enabled:
922    ///
923    /// ```
924    /// # #[cfg(not(feature = "std"))]
925    /// # fn main() {
926    /// # }
927    /// # #[cfg(feature = "std")]
928    /// # fn main() {
929    /// use std::collections::{HashMap, HashSet};
930    /// use asserting::prelude::*;
931    ///
932    /// let some_set: HashSet<u8> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
933    /// assert_that!(some_set).has_length(8);
934    ///
935    /// let some_map: HashMap<char, usize> = [('A', 25), ('B', 2), ('C', 12), ('D', 18)].into_iter().collect();
936    /// assert_that!(&some_map).has_length(4);
937    /// # }
938    /// ```
939    #[track_caller]
940    fn has_length(self, expected_length: E) -> Self;
941
942    /// Verifies that the subject has a length in the expected range.
943    ///
944    /// The expected range can be any type of range.
945    ///
946    /// # Examples
947    ///
948    /// ```
949    /// use std::collections::{BTreeSet, VecDeque};
950    /// use asserting::prelude::*;
951    ///
952    /// let some_str = "takimata te iriure nonummy";
953    /// assert_that!(some_str).has_length_in_range(12..32);
954    /// assert_that!(some_str).has_length_in_range(12..=32);
955    /// assert_that!(some_str).has_length_in_range(12..);
956    /// assert_that!(some_str).has_length_in_range(..32);
957    /// assert_that!(some_str).has_length_in_range(..=32);
958    ///
959    /// let some_vec = vec!['m', 'Q', 'k', 'b'];
960    /// assert_that!(&some_vec).has_length_in_range(2..6);
961    /// assert_that!(&some_vec).has_length_in_range(2..=6);
962    /// assert_that!(&some_vec).has_length_in_range(2..);
963    /// assert_that!(&some_vec).has_length_in_range(..6);
964    /// assert_that!(&some_vec).has_length_in_range(..=6);
965    ///
966    /// let some_btree_set = BTreeSet::from_iter([1, 3, 5, 7, 11, 13, 17, 19]);
967    /// assert_that!(&some_btree_set).has_length_in_range(6..10);
968    /// assert_that!(&some_btree_set).has_length_in_range(6..=10);
969    /// assert_that!(&some_btree_set).has_length_in_range(8..);
970    /// assert_that!(&some_btree_set).has_length_in_range(..9);
971    /// assert_that!(&some_btree_set).has_length_in_range(..=8);
972    ///
973    /// let some_dequeue = VecDeque::from_iter(["one", "two", "three"]);
974    /// assert_that!(&some_dequeue).has_length_in_range(2..5);
975    /// assert_that!(&some_dequeue).has_length_in_range(2..=5);
976    /// assert_that!(&some_dequeue).has_length_in_range(3..);
977    /// assert_that!(&some_dequeue).has_length_in_range(..4);
978    /// assert_that!(&some_dequeue).has_length_in_range(..=3);
979    /// ```
980    ///
981    /// with crate feature `std` enabled:
982    ///
983    /// ```
984    /// # #[cfg(not(feature = "std"))]
985    /// # fn main() {
986    /// # }
987    /// # #[cfg(feature = "std")]
988    /// # fn main() {
989    /// use std::collections::{HashMap, HashSet};
990    /// use asserting::prelude::*;
991    ///
992    /// let some_set: HashSet<u8> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
993    /// assert_that!(&some_set).has_length_in_range(4..12);
994    /// assert_that!(&some_set).has_length_in_range(4..=12);
995    /// assert_that!(&some_set).has_length_in_range(8..);
996    /// assert_that!(&some_set).has_length_in_range(..9);
997    /// assert_that!(&some_set).has_length_in_range(..=8);
998    ///
999    /// let some_map: HashMap<char, usize> = [('A', 25), ('B', 2), ('C', 12), ('D', 18)].into_iter().collect();
1000    /// assert_that!(&some_map).has_length_in_range(2..8);
1001    /// assert_that!(&some_map).has_length_in_range(2..=8);
1002    /// assert_that!(&some_map).has_length_in_range(4..);
1003    /// assert_that!(&some_map).has_length_in_range(..5);
1004    /// assert_that!(&some_map).has_length_in_range(..=4);
1005    /// # }
1006    /// ```
1007    #[track_caller]
1008    fn has_length_in_range<U>(self, expected_range: U) -> Self
1009    where
1010        U: RangeBounds<usize> + Debug;
1011
1012    /// Verifies that the subject has a length that is less than the expected
1013    /// length.
1014    ///
1015    /// # Examples
1016    ///
1017    /// ```
1018    /// use std::collections::{BTreeSet, VecDeque};
1019    /// use asserting::prelude::*;
1020    ///
1021    /// let some_str = "takimata te iriure nonummy";
1022    /// assert_that!(some_str).has_length_less_than(40);
1023    /// assert_that!(some_str).has_length_less_than(27);
1024    ///
1025    /// let some_vec = vec!['m', 'Q', 'k', 'b'];
1026    /// assert_that!(&some_vec).has_length_less_than(10);
1027    /// assert_that!(&some_vec).has_length_less_than(5);
1028    ///
1029    /// let some_btree_set = BTreeSet::from_iter([1, 3, 5, 7, 11, 13, 17, 19]);
1030    /// assert_that!(&some_btree_set).has_length_less_than(20);
1031    /// assert_that!(&some_btree_set).has_length_less_than(9);
1032    ///
1033    /// let some_dequeue = VecDeque::from_iter(["one", "two", "three"]);
1034    /// assert_that!(&some_dequeue).has_length_less_than(10);
1035    /// assert_that!(&some_dequeue).has_length_less_than(4);
1036    /// ```
1037    ///
1038    /// with crate feature `std` enabled:
1039    ///
1040    /// ```
1041    /// # #[cfg(not(feature = "std"))]
1042    /// # fn main() {
1043    /// # }
1044    /// # #[cfg(feature = "std")]
1045    /// # fn main() {
1046    /// use std::collections::{HashMap, HashSet};
1047    /// use asserting::prelude::*;
1048    ///
1049    /// let some_set: HashSet<u8> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
1050    /// assert_that!(&some_set).has_length_less_than(15);
1051    /// assert_that!(&some_set).has_length_less_than(9);
1052    ///
1053    /// let some_map: HashMap<char, usize> = [('A', 25), ('B', 2), ('C', 12), ('D', 18)].into_iter().collect();
1054    /// assert_that!(&some_map).has_length_less_than(10);
1055    /// assert_that!(&some_map).has_length_less_than(5);
1056    /// # }
1057    /// ```
1058    #[track_caller]
1059    fn has_length_less_than(self, expected_length: E) -> Self;
1060
1061    /// Verifies that the subject has a length that is greater than the expected
1062    /// length.
1063    ///
1064    /// # Examples
1065    ///
1066    /// ```
1067    /// use std::collections::{BTreeSet, VecDeque};
1068    /// use asserting::prelude::*;
1069    ///
1070    /// let some_str = "takimata te iriure nonummy";
1071    /// assert_that!(some_str).has_length_greater_than(20);
1072    /// assert_that!(some_str).has_length_greater_than(25);
1073    ///
1074    /// let some_vec = vec!['m', 'Q', 'k', 'b'];
1075    /// assert_that!(&some_vec).has_length_greater_than(1);
1076    /// assert_that!(&some_vec).has_length_greater_than(3);
1077    ///
1078    /// let some_btree_set = BTreeSet::from_iter([1, 3, 5, 7, 11, 13, 17, 19]);
1079    /// assert_that!(&some_btree_set).has_length_greater_than(4);
1080    /// assert_that!(&some_btree_set).has_length_greater_than(7);
1081    ///
1082    /// let some_dequeue = VecDeque::from_iter(["one", "two", "three"]);
1083    /// assert_that!(&some_dequeue).has_length_greater_than(1);
1084    /// assert_that!(&some_dequeue).has_length_greater_than(2);
1085    /// ```
1086    ///
1087    /// with crate feature `std` enabled:
1088    ///
1089    /// ```
1090    /// # #[cfg(not(feature = "std"))]
1091    /// # fn main() {
1092    /// # }
1093    /// # #[cfg(feature = "std")]
1094    /// # fn main() {
1095    /// use std::collections::{HashMap, HashSet};
1096    /// use asserting::prelude::*;
1097    ///
1098    /// let some_set: HashSet<u8> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
1099    /// assert_that!(&some_set).has_length_greater_than(4);
1100    /// assert_that!(&some_set).has_length_greater_than(7);
1101    ///
1102    /// let some_map: HashMap<char, usize> = [('A', 25), ('B', 2), ('C', 12), ('D', 18)].into_iter().collect();
1103    /// assert_that!(&some_map).has_length_greater_than(2);
1104    /// assert_that!(&some_map).has_length_greater_than(3);
1105    /// # }
1106    /// ```
1107    #[track_caller]
1108    fn has_length_greater_than(self, expected_length: E) -> Self;
1109
1110    /// Verifies that the subject has a length that is at most the expected
1111    /// length.
1112    ///
1113    /// In other words, the length shall be less than or equal to the expected
1114    /// length.
1115    ///
1116    /// # Examples
1117    ///
1118    /// ```
1119    /// use std::collections::{BTreeSet, VecDeque};
1120    /// use asserting::prelude::*;
1121    ///
1122    /// let some_str = "takimata te iriure nonummy";
1123    /// assert_that!(some_str).has_at_most_length(30);
1124    /// assert_that!(some_str).has_at_most_length(26);
1125    ///
1126    /// let some_vec = vec!['m', 'Q', 'k', 'b'];
1127    /// assert_that!(&some_vec).has_at_most_length(10);
1128    /// assert_that!(&some_vec).has_at_most_length(4);
1129    ///
1130    /// let some_btree_set = BTreeSet::from_iter([1, 3, 5, 7, 11, 13, 17, 19]);
1131    /// assert_that!(&some_btree_set).has_at_most_length(12);
1132    /// assert_that!(&some_btree_set).has_at_most_length(8);
1133    ///
1134    /// let some_dequeue = VecDeque::from_iter(["one", "two", "three"]);
1135    /// assert_that!(&some_dequeue).has_at_most_length(10);
1136    /// assert_that!(&some_dequeue).has_at_most_length(3);
1137    /// ```
1138    ///
1139    /// with crate feature `std` enabled:
1140    ///
1141    /// ```
1142    /// # #[cfg(not(feature = "std"))]
1143    /// # fn main() {
1144    /// # }
1145    /// # #[cfg(feature = "std")]
1146    /// # fn main() {
1147    /// use std::collections::{HashMap, HashSet};
1148    /// use asserting::prelude::*;
1149    ///
1150    /// let some_set: HashSet<u8> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
1151    /// assert_that!(&some_set).has_at_most_length(15);
1152    /// assert_that!(&some_set).has_at_most_length(8);
1153    ///
1154    /// let some_map: HashMap<char, usize> = [('A', 25), ('B', 2), ('C', 12), ('D', 18)].into_iter().collect();
1155    /// assert_that!(&some_map).has_at_most_length(10);
1156    /// assert_that!(&some_map).has_at_most_length(4);
1157    /// # }
1158    /// ```
1159    #[track_caller]
1160    fn has_at_most_length(self, expected_length: E) -> Self;
1161
1162    /// Verifies that the subject has a length that is at least the expected
1163    /// length.
1164    ///
1165    /// In other words, the length shall be greater than or equal to the
1166    /// expected length.
1167    ///
1168    /// # Examples
1169    ///
1170    /// ```
1171    /// use std::collections::{BTreeSet, VecDeque};
1172    /// use asserting::prelude::*;
1173    ///
1174    /// let some_str = "takimata te iriure nonummy";
1175    /// assert_that!(some_str).has_at_least_length(20);
1176    /// assert_that!(some_str).has_at_least_length(26);
1177    ///
1178    /// let some_vec = vec!['m', 'Q', 'k', 'b'];
1179    /// assert_that!(&some_vec).has_at_least_length(1);
1180    /// assert_that!(&some_vec).has_at_least_length(4);
1181    ///
1182    /// let some_btree_set = BTreeSet::from_iter([1, 3, 5, 7, 11, 13, 17, 19]);
1183    /// assert_that!(&some_btree_set).has_at_least_length(4);
1184    /// assert_that!(&some_btree_set).has_at_least_length(8);
1185    ///
1186    /// let some_dequeue = VecDeque::from_iter(["one", "two", "three"]);
1187    /// assert_that!(&some_dequeue).has_at_least_length(1);
1188    /// assert_that!(&some_dequeue).has_at_least_length(3);
1189    /// ```
1190    ///
1191    /// with crate feature `std` enabled:
1192    ///
1193    /// ```
1194    /// # #[cfg(not(feature = "std"))]
1195    /// # fn main() {
1196    /// # }
1197    /// # #[cfg(feature = "std")]
1198    /// # fn main() {
1199    /// use std::collections::{HashMap, HashSet};
1200    /// use asserting::prelude::*;
1201    ///
1202    /// let some_set: HashSet<u8> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
1203    /// assert_that!(&some_set).has_at_least_length(4);
1204    /// assert_that!(&some_set).has_at_least_length(8);
1205    ///
1206    /// let some_map: HashMap<char, usize> = [('A', 25), ('B', 2), ('C', 12), ('D', 18)].into_iter().collect();
1207    /// assert_that!(&some_map).has_at_least_length(2);
1208    /// assert_that!(&some_map).has_at_least_length(4);
1209    /// # }
1210    /// ```
1211    #[track_caller]
1212    fn has_at_least_length(self, expected_length: E) -> Self;
1213}
1214
1215/// Assert the number of characters contained in a string or similar container.
1216///
1217/// These assertions are implemented for all types `T` that implement the trait
1218/// [`CharCountProperty`](crate::properties::CharCountProperty). This property
1219/// is implemented for `String` and `&str`.
1220///
1221/// # Examples
1222///
1223/// ```
1224/// use asserting::prelude::*;
1225///
1226/// let subject = "imper \u{0180} diet al \u{02AA} \u{01AF} zzril";
1227/// assert_that!(subject).has_length(28);
1228/// assert_that!(subject).has_char_count(25);
1229///
1230/// let subject = "imper diet al zzril";
1231/// assert_that!(subject).has_length(19);
1232/// assert_that!(subject).has_char_count(19);
1233///
1234/// let subject = "imper \u{0180} diet al \u{02AA} \u{01AF} zzril";
1235/// assert_that!(subject).has_char_count_in_range(12..=36);
1236/// assert_that!(subject).has_char_count_less_than(26);
1237/// assert_that!(subject).has_char_count_greater_than(24);
1238/// assert_that!(subject).has_at_most_char_count(30);
1239/// assert_that!(subject).has_at_most_char_count(25);
1240/// assert_that!(subject).has_at_least_char_count(20);
1241/// assert_that!(subject).has_at_least_char_count(25);
1242/// ```
1243pub trait AssertHasCharCount<E> {
1244    /// Verifies that the subject contains the expected number of characters.
1245    ///
1246    /// # Examples
1247    ///
1248    /// ```
1249    /// use asserting::prelude::*;
1250    ///
1251    /// let subject = "imper \u{0180} diet al \u{02AA} \u{01AF} zzril";
1252    /// assert_that!(subject).has_length(28);
1253    /// assert_that!(subject).has_char_count(25);
1254    ///
1255    /// let subject = "imper diet al zzril";
1256    /// assert_that!(subject).has_length(19);
1257    /// assert_that!(subject).has_char_count(19);
1258    /// ```
1259    #[track_caller]
1260    fn has_char_count(self, expected: E) -> Self;
1261
1262    /// Verifies that the subject contains a number of characters that is in the
1263    /// expected range.
1264    ///
1265    /// The expected range must be a closed range with both ends inclusive.
1266    ///
1267    /// # Examples
1268    ///
1269    /// ```
1270    /// use asserting::prelude::*;
1271    ///
1272    /// let subject = "imper \u{0180} diet al \u{02AA} \u{01AF} zzril";
1273    /// assert_that!(subject).has_char_count_in_range(12..36);
1274    /// assert_that!(subject).has_char_count_in_range(12..=36);
1275    /// ```
1276    #[track_caller]
1277    fn has_char_count_in_range<U>(self, range: U) -> Self
1278    where
1279        U: RangeBounds<usize> + Debug;
1280
1281    /// Verifies that the subject contains less than the expected number of
1282    /// characters.
1283    ///
1284    /// # Examples
1285    ///
1286    /// ```
1287    /// use asserting::prelude::*;
1288    ///
1289    /// let subject = "imper \u{0180} diet al \u{02AA} \u{01AF} zzril";
1290    /// assert_that!(subject).has_char_count_less_than(26);
1291    /// ```
1292    #[track_caller]
1293    fn has_char_count_less_than(self, expected: E) -> Self;
1294
1295    /// Verifies that the subject contains more than the expected number of
1296    /// characters.
1297    ///
1298    /// # Examples
1299    ///
1300    /// ```
1301    /// use asserting::prelude::*;
1302    ///
1303    /// let subject = "imper \u{0180} diet al \u{02AA} \u{01AF} zzril";
1304    /// assert_that!(subject).has_char_count_greater_than(24);
1305    /// ```
1306    #[track_caller]
1307    fn has_char_count_greater_than(self, expected: E) -> Self;
1308
1309    /// Verifies that the subject contains at least the expected number of
1310    /// characters.
1311    ///
1312    /// In other words, the number of characters shall be less than or equal
1313    /// to the expected number.
1314    ///
1315    /// # Examples
1316    ///
1317    /// ```
1318    /// use asserting::prelude::*;
1319    ///
1320    /// let subject = "imper \u{0180} diet al \u{02AA} \u{01AF} zzril";
1321    /// assert_that!(subject).has_at_most_char_count(30);
1322    /// assert_that!(subject).has_at_most_char_count(25);
1323    /// ```
1324    #[track_caller]
1325    fn has_at_most_char_count(self, expected: E) -> Self;
1326
1327    /// Verifies that the subject contains at least the expected number of
1328    /// characters.
1329    ///
1330    /// In other words, the number of characters shall be greater than or equal
1331    /// to the expected number.
1332    ///
1333    /// # Examples
1334    ///
1335    /// ```
1336    /// use asserting::prelude::*;
1337    ///
1338    /// let subject = "imper \u{0180} diet al \u{02AA} \u{01AF} zzril";
1339    /// assert_that!(subject).has_at_least_char_count(20);
1340    /// assert_that!(subject).has_at_least_char_count(25);
1341    /// ```
1342    #[track_caller]
1343    fn has_at_least_char_count(self, expected: E) -> Self;
1344}
1345
1346/// Assert whether a subject of the `Option` type holds some value or has none.
1347///
1348/// # Examples
1349///
1350/// ```
1351/// use asserting::prelude::*;
1352///
1353/// let subject = Some("nisl possim nobis non".to_string());
1354/// assert_that!(subject).is_some();
1355///
1356/// #[derive(Debug)]
1357/// struct MyType;
1358///
1359/// let subject: Option<MyType> = None;
1360/// assert_that!(subject).is_none();
1361/// ```
1362pub trait AssertOption {
1363    /// Verifies that the subject has some value.
1364    ///
1365    /// # Examples
1366    ///
1367    /// ```
1368    /// use asserting::prelude::*;
1369    ///
1370    /// let subject = Some("nisl possim nobis non".to_string());
1371    /// assert_that!(subject).is_some();
1372    ///
1373    /// #[derive(Debug)]
1374    /// struct MyType;
1375    ///
1376    /// let subject = Some(MyType);
1377    /// assert_that!(subject).is_some();
1378    /// ```
1379    #[track_caller]
1380    fn is_some(self) -> Self;
1381
1382    /// Verifies that the subject has no value.
1383    ///
1384    /// # Examples
1385    ///
1386    /// ```
1387    /// use asserting::prelude::*;
1388    ///
1389    /// let subject: Option<String> = None;
1390    /// assert_that!(subject).is_none();
1391    ///
1392    /// #[derive(Debug)]
1393    /// struct MyType;
1394    ///
1395    /// let subject: Option<MyType> = None;
1396    /// assert_that!(subject).is_none();
1397    /// ```
1398    #[track_caller]
1399    fn is_none(self) -> Self;
1400}
1401
1402/// Assert the option value by mapping the subject.
1403///
1404/// If the option is none, the assertion fails.
1405///
1406/// # Examples
1407///
1408/// ```
1409/// use asserting::prelude::*;
1410///
1411/// let subject: Option<Vec<usize>> = Some(vec![1, 2, 3]);
1412/// assert_that!(subject).some().contains_exactly([1, 2, 3]);
1413///
1414/// let subject: Option<&str> = Some("ullamco cupiditat diam hendrerit");
1415/// assert_that!(subject).some().is_not_empty();
1416/// ```
1417pub trait AssertOptionValue<'a, T, R> {
1418    /// Maps the subject to the option's value if it has some. Otherwise, this
1419    /// assertion fails.
1420    ///
1421    /// # Examples
1422    ///
1423    /// ```
1424    /// use asserting::prelude::*;
1425    ///
1426    /// let subject: Option<Vec<usize>> = Some(vec![1, 2, 3]);
1427    /// assert_that!(subject).some().contains_exactly([1, 2, 3]);
1428    ///
1429    /// let subject: Option<&str> = Some("ullamco cupiditat diam hendrerit");
1430    /// assert_that!(subject).some().is_not_empty();
1431    /// ```
1432    #[track_caller]
1433    fn some(self) -> Spec<'a, T, R>;
1434}
1435
1436/// Assert whether a subject of the `Result` type holds some value or an error.
1437///
1438/// # Examples
1439///
1440/// ```
1441/// use asserting::prelude::*;
1442///
1443/// let subject: Result<f64, String> = Ok(-3.14);
1444/// assert_that!(subject).is_ok();
1445///
1446/// let subject: Result<(), String> = Err("consequat sanctus ea exercitation".to_string());
1447/// assert_that!(subject).is_err();
1448/// ```
1449pub trait AssertResult {
1450    /// Verifies that the subject has an ok value.
1451    ///
1452    /// # Examples
1453    ///
1454    /// ```
1455    /// use asserting::prelude::*;
1456    ///
1457    /// let subject: Result<f64, String> = Ok(-3.14);
1458    /// assert_that!(subject).is_ok();
1459    /// ```
1460    #[track_caller]
1461    fn is_ok(self) -> Self;
1462
1463    /// Verifies that the subject has an err value.
1464    ///
1465    /// # Examples
1466    ///
1467    /// ```
1468    /// use asserting::prelude::*;
1469    ///
1470    /// let subject: Result<(), String> = Err("consequat sanctus ea exercitation".to_string());
1471    /// assert_that!(subject).is_err();
1472    /// ```
1473    #[track_caller]
1474    fn is_err(self) -> Self;
1475}
1476
1477/// Assert the result value or error by mapping the subject.
1478///
1479/// # Examples
1480///
1481/// ```
1482/// use asserting::prelude::*;
1483///
1484/// let subject: Result<Vec<usize>, String> = Ok(vec![1, 2, 3]);
1485/// assert_that!(subject).ok().is_not_empty();
1486///
1487/// let subject: Result<u64, String> = Err("te anim adipisici mollit".to_string());
1488/// assert_that!(subject).err().is_equal_to("te anim adipisici mollit");
1489/// ```
1490pub trait AssertResultValue<'a, T, E, R> {
1491    /// Maps the subject to the result's ok value.
1492    ///
1493    /// If the result is an error, this method panics.
1494    ///
1495    /// # Examples
1496    ///
1497    /// ```
1498    /// use asserting::prelude::*;
1499    ///
1500    /// let subject: Result<Vec<usize>, String> = Ok(vec![1, 2, 3]);
1501    /// assert_that!(subject).ok().is_not_empty();
1502    /// ```
1503    #[track_caller]
1504    fn ok(self) -> Spec<'a, T, R>;
1505
1506    /// Maps the subject to the result's err value.
1507    ///
1508    /// If the result is an ok value, this method panics.
1509    ///
1510    /// # Examples
1511    ///
1512    /// ```
1513    /// use asserting::prelude::*;
1514    ///
1515    /// let subject: Result<u64, String> = Err("te anim adipisici mollit".to_string());
1516    /// assert_that!(subject).err().is_equal_to("te anim adipisici mollit");
1517    /// ```
1518    #[track_caller]
1519    fn err(self) -> Spec<'a, E, R>;
1520}
1521
1522/// Assert that a subject of some container type holds a value that is equal to
1523/// the expected one.
1524///
1525/// This assertion is implemented for the `Option` type and the `Result` type.
1526/// For `Option` it compares the value to the expected one if it has some or
1527/// fails if it holds none. For `Result` it compares the ok value to the
1528/// expected one if it is an ok or fails if it holds an error.
1529///
1530/// The value type of the `Option` or `Result` must implement `PartialEq<E>`
1531/// where `E` is the type of the expected value.
1532///
1533/// To assert the error value of a `Result` use [`AssertHasError::has_error`].
1534///
1535/// # Examples
1536///
1537/// ```
1538/// use asserting::prelude::*;
1539///
1540/// let subject = Some(-3.14);
1541/// assert_that!(subject).has_value(-3.14);
1542///
1543/// let subject: Result<f64, String> = Ok(6.28);
1544/// assert_that!(subject).has_value(6.28);
1545/// ```
1546pub trait AssertHasValue<E> {
1547    /// Verifies that the subject holds a value that is equal to the expected
1548    /// one.
1549    ///
1550    /// For `Option` it compares the value in `Some(value)` and for `Result`
1551    /// it compares the value in `Ok(value)`. If an `Option` is `None` or a
1552    /// `Result` is `Err(error)` then the assertion fails.
1553    ///
1554    /// # Examples
1555    ///
1556    /// ```
1557    /// use asserting::prelude::*;
1558    ///
1559    /// let subject = Some(-3.14);
1560    /// assert_that!(subject).has_value(-3.14);
1561    ///
1562    /// let subject: Result<f64, String> = Ok(6.28);
1563    /// assert_that!(subject).has_value(6.28);
1564    /// ```
1565    #[track_caller]
1566    fn has_value(self, expected: E) -> Self;
1567}
1568
1569/// Assert that a subject of some container type holds an error value that is
1570/// equal to the expected one.
1571///
1572/// This assertion is implemented for the `Result` type. It compares the value
1573/// in `Err(value)` with the expected one. The error type in the `Result` must
1574/// implement `PartialEq<E>` where `E` is the type of the expected error value.
1575///
1576/// To assert the ok value of a `Result` use [`AssertHasValue::has_value`].
1577///
1578/// # Examples
1579///
1580/// ```
1581/// use asserting::prelude::*;
1582///
1583/// let subject: Result<(), String> = Err("labore gubergren ut ipsum".to_string());
1584/// assert_that!(subject).has_error("labore gubergren ut ipsum");
1585/// ```
1586pub trait AssertHasError<E> {
1587    /// Verifies that the subject holds an error value that is equal to the
1588    /// expected one.
1589    ///
1590    /// For `Result` it compares the value in `Err(value)`. If the `Result`
1591    /// holds an `Ok(value)`, the assertion fails.
1592    ///
1593    /// # Examples
1594    ///
1595    /// ```
1596    /// use asserting::prelude::*;
1597    ///
1598    /// let subject: Result<(), String> = Err("labore gubergren ut ipsum".to_string());
1599    /// assert_that!(subject).has_error("labore gubergren ut ipsum");
1600    /// ```
1601    #[track_caller]
1602    fn has_error(self, expected: E) -> Self;
1603}
1604
1605/// Assert that a subject of some container type holds an error value that has
1606/// a message equal to the expected message.
1607///
1608/// This is useful for opaque error types that do not implement
1609/// `PartialEq`. Since the `std::error::Error` trait requires that error
1610/// types implement `Display`, the string representation of the error value
1611/// is compared to an expected message string.
1612///
1613/// This assertion is implemented for the `Result` type. It compares the string
1614/// representation of the error value with the expected message.
1615///
1616/// To assert the ok value of a `Result` use [`AssertHasValue::has_value`].
1617///
1618/// # Examples
1619///
1620/// ```
1621/// use anyhow::anyhow;
1622/// use asserting::prelude::*;
1623///
1624/// let subject: Result<(), anyhow::Error> = Err(anyhow!("mollit in ullamcorper no".to_string()));
1625/// assert_that!(subject).has_error_message("mollit in ullamcorper no");
1626/// ```
1627pub trait AssertHasErrorMessage<'a, E, R> {
1628    /// Verifies that the subject is an error value with the expected message.
1629    ///
1630    /// This is useful for opaque error types that do not implement
1631    /// `PartialEq`. Since the `std::error::Error` trait requires that error
1632    /// types implement `Display`, the string representation of the error value
1633    /// is compared to an expected message string.
1634    ///
1635    /// This method panics if the actual subject is not an error value.
1636    ///
1637    /// # Examples
1638    ///
1639    /// ```
1640    /// use anyhow::anyhow;
1641    /// use asserting::prelude::*;
1642    ///
1643    /// let subject: Result<(), anyhow::Error> = Err(anyhow!("mollit in ullamcorper no".to_string()));
1644    /// assert_that!(subject).has_error_message("mollit in ullamcorper no");
1645    /// ```
1646    #[track_caller]
1647    fn has_error_message(self, expected_message: E) -> Spec<'a, String, R>;
1648}
1649
1650/// Assert the source of any type that implements `std::error::Error`.
1651///
1652/// # Examples
1653///
1654/// ```
1655/// use asserting::prelude::*;
1656/// use std::error::Error;
1657/// use std::fmt::{self, Display};
1658///
1659/// #[derive(Debug)]
1660/// struct SuperError {
1661///     source: SourceError,
1662/// }
1663///
1664/// impl Display for SuperError {
1665///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1666///         write!(f, "super-error caused by {}", self.source)
1667///     }
1668/// }
1669///
1670/// impl Error for SuperError {
1671///     fn source(&self) -> Option<&(dyn Error + 'static)> {
1672///         Some(&self.source)
1673///     }
1674/// }
1675///
1676/// #[derive(Debug, PartialEq)]
1677/// enum SourceError {
1678///     Foo,
1679///     Bar,
1680/// }
1681///
1682/// impl Display for SourceError {
1683///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1684///         match self {
1685///             Self::Foo => f.write_str("foo error"),
1686///             Self::Bar => f.write_str("bar error"),
1687///         }
1688///     }
1689/// }
1690///
1691/// impl Error for SourceError {}
1692///
1693///
1694/// let error = SuperError {
1695///     source: SourceError::Foo,
1696/// };
1697///
1698/// assert_that!(&error).has_source();
1699/// assert_that!(&error).has_source_message("foo error");
1700/// ```
1701pub trait AssertErrorHasSource<'a, R> {
1702    /// Verifies that an error has no source.
1703    ///
1704    /// # Example
1705    ///
1706    /// ```
1707    /// use asserting::prelude::*;
1708    /// use std::error::Error;
1709    /// use std::fmt::{self, Display};
1710    ///
1711    /// #[derive(Debug, PartialEq)]
1712    /// enum SimpleError {
1713    ///     Foo,
1714    ///     Bar,
1715    /// }
1716    ///
1717    /// impl Display for SimpleError {
1718    ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1719    ///         match self {
1720    ///             Self::Foo => f.write_str("foo error"),
1721    ///             Self::Bar => f.write_str("bar error"),
1722    ///         }
1723    ///     }
1724    /// }
1725    ///
1726    /// impl Error for SimpleError {}
1727    ///
1728    ///
1729    /// let error = SimpleError::Bar;
1730    ///
1731    /// assert_that!(&error).has_no_source();
1732    /// ```
1733    #[track_caller]
1734    fn has_no_source(self) -> Self;
1735
1736    /// Verifies that an error has some source.
1737    ///
1738    /// # Example
1739    ///
1740    /// ```
1741    /// use asserting::prelude::*;
1742    /// use std::error::Error;
1743    /// use std::fmt::{self, Display};
1744    ///
1745    /// #[derive(Debug)]
1746    /// struct SuperError {
1747    ///     source: SourceError,
1748    /// }
1749    ///
1750    /// impl Display for SuperError {
1751    ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1752    ///         write!(f, "super-error caused by {}", self.source)
1753    ///     }
1754    /// }
1755    ///
1756    /// impl Error for SuperError {
1757    ///     fn source(&self) -> Option<&(dyn Error + 'static)> {
1758    ///         Some(&self.source)
1759    ///     }
1760    /// }
1761    ///
1762    /// #[derive(Debug, PartialEq)]
1763    /// enum SourceError {
1764    ///     Foo,
1765    ///     Bar,
1766    /// }
1767    ///
1768    /// impl Display for SourceError {
1769    ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1770    ///         match self {
1771    ///             Self::Foo => f.write_str("foo error"),
1772    ///             Self::Bar => f.write_str("bar error"),
1773    ///         }
1774    ///     }
1775    /// }
1776    ///
1777    /// impl Error for SourceError {}
1778    ///
1779    ///
1780    /// let error = SuperError {
1781    ///     source: SourceError::Foo,
1782    /// };
1783    ///
1784    /// assert_that!(&error).has_source();
1785    /// ```
1786    #[track_caller]
1787    fn has_source(self) -> Self;
1788
1789    /// Verifies that an error has some source which converted to a string
1790    /// equals the expected message.
1791    ///
1792    /// # Example
1793    ///
1794    /// ```
1795    /// use asserting::prelude::*;
1796    /// use std::error::Error;
1797    /// use std::fmt::{self, Display};
1798    ///
1799    /// #[derive(Debug)]
1800    /// struct SuperError {
1801    ///     source: SourceError,
1802    /// }
1803    ///
1804    /// impl Display for SuperError {
1805    ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1806    ///         write!(f, "super-error caused by {}", self.source)
1807    ///     }
1808    /// }
1809    ///
1810    /// impl Error for SuperError {
1811    ///     fn source(&self) -> Option<&(dyn Error + 'static)> {
1812    ///         Some(&self.source)
1813    ///     }
1814    /// }
1815    ///
1816    /// #[derive(Debug, PartialEq)]
1817    /// enum SourceError {
1818    ///     Foo,
1819    ///     Bar,
1820    /// }
1821    ///
1822    /// impl Display for SourceError {
1823    ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1824    ///         match self {
1825    ///             Self::Foo => f.write_str("foo error"),
1826    ///             Self::Bar => f.write_str("bar error"),
1827    ///         }
1828    ///     }
1829    /// }
1830    ///
1831    /// impl Error for SourceError {}
1832    ///
1833    ///
1834    /// let error = SuperError {
1835    ///     source: SourceError::Bar,
1836    /// };
1837    ///
1838    /// assert_that!(&error).has_source_message("bar error");
1839    /// ```
1840    #[track_caller]
1841    fn has_source_message(
1842        self,
1843        expected_source_message: impl Into<String>,
1844    ) -> Spec<'a, Option<String>, R>;
1845}
1846
1847/// Assert that a string contains a substring or character.
1848///
1849/// # Examples
1850///
1851/// ```
1852/// use asserting::prelude::*;
1853///
1854/// let subject = "doming vulputate proident eum";
1855///
1856/// assert_that!(subject).contains("tate p");
1857/// assert_that!(subject).contains('u');
1858/// assert_that!(subject).starts_with("dom");
1859/// assert_that!(subject).starts_with('d');
1860/// assert_that!(subject).ends_with("t eum");
1861/// assert_that!(subject).ends_with('m');
1862/// ```
1863pub trait AssertStringPattern<E> {
1864    /// Verifies that a string contains a substring or character.
1865    ///
1866    /// # Examples
1867    ///
1868    /// ```
1869    /// use asserting::prelude::*;
1870    ///
1871    /// let subject = "doming vulputate proident eum";
1872    ///
1873    /// assert_that!(subject).contains("tate p");
1874    /// assert_that!(subject).contains('u');
1875    /// ```
1876    #[track_caller]
1877    fn contains(self, pattern: E) -> Self;
1878
1879    /// Verifies that a string starts with a substring or character.
1880    ///
1881    /// # Examples
1882    ///
1883    /// ```
1884    /// use asserting::prelude::*;
1885    ///
1886    /// let subject = "doming vulputate proident eum";
1887    ///
1888    /// assert_that!(subject).starts_with("dom");
1889    /// assert_that!(subject).starts_with('d');
1890    /// ```
1891    #[track_caller]
1892    fn starts_with(self, pattern: E) -> Self;
1893
1894    /// Verifies that a string ends with a substring or character.
1895    ///
1896    /// # Examples
1897    ///
1898    /// ```
1899    /// use asserting::prelude::*;
1900    ///
1901    /// let subject = "doming vulputate proident eum";
1902    ///
1903    /// assert_that!(subject).ends_with("t eum");
1904    /// assert_that!(subject).ends_with('m');
1905    /// ```
1906    #[track_caller]
1907    fn ends_with(self, pattern: E) -> Self;
1908}
1909
1910/// Assert that a string contains any char from a collection of chars.
1911///
1912/// # Examples
1913///
1914/// ```
1915/// use asserting::prelude::*;
1916///
1917/// let subject = "vel aliquip doming eros";
1918///
1919/// assert_that!(subject).contains_any_of(['a', 'b', 'm', 'z']);
1920/// assert_that!(subject).contains_any_of(&['a', 'b', 'm', 'z']);
1921/// assert_that!(subject).contains_any_of(&['a', 'b', 'm', 'z'][..]);
1922/// ```
1923pub trait AssertStringContainsAnyOf<E> {
1924    /// Verifies that a string contains any char from a collection of chars.
1925    ///
1926    /// # Examples
1927    ///
1928    /// ```
1929    /// use asserting::prelude::*;
1930    ///
1931    /// let subject = "vel aliquip doming eros";
1932    ///
1933    /// assert_that!(subject).contains_any_of(['a', 'b', 'm', 'z']);
1934    /// assert_that!(subject).contains_any_of(&['a', 'b', 'm', 'z']);
1935    /// assert_that!(subject).contains_any_of(&['a', 'b',  'm', 'z'][..]);
1936    /// ```
1937    #[track_caller]
1938    fn contains_any_of(self, pattern: E) -> Self;
1939}
1940
1941/// Assert that a string matches a regex pattern.
1942///
1943/// # Example
1944///
1945/// ```
1946/// # #[cfg(not(feature = "regex"))]
1947/// # fn main() {}
1948/// # #[cfg(feature = "regex")]
1949/// # fn main() {
1950/// use asserting::prelude::*;
1951///
1952/// assert_that("tation odio placerat in").matches(r"\b\w{8}\b");
1953/// # }
1954/// ```
1955#[cfg(feature = "regex")]
1956#[cfg_attr(docsrs, doc(cfg(feature = "regex")))]
1957pub trait AssertStringMatches {
1958    /// Verifies that a string matches the given regex pattern.
1959    ///
1960    /// # Example
1961    ///
1962    /// ```
1963    /// # #[cfg(not(feature = "regex"))]
1964    /// # fn main() {}
1965    /// # #[cfg(feature = "regex")]
1966    /// # fn main() {
1967    /// use asserting::prelude::*;
1968    ///
1969    /// assert_that("tation odio placerat in").matches(r"\b\w{8}\b");
1970    /// # }
1971    /// ```
1972    #[track_caller]
1973    fn matches(self, regex_pattern: &str) -> Self;
1974}
1975
1976/// Assert that an iterator or collection contains the expected value.
1977///
1978/// This assertion is implemented for any collection or iterator of items that
1979/// implement `PartialEq<E>` with `E` being the type of the expected value.
1980///
1981/// # Examples
1982///
1983/// ```
1984/// use asserting::prelude::*;
1985/// use std::collections::BTreeMap;
1986///
1987/// let some_array = [1, 3, 5, 7];
1988/// assert_that!(some_array).contains(5);
1989///
1990/// let some_slice = &['b', 'X', 'k', 'G'][..];
1991/// assert_that!(some_slice).contains(&'X');
1992///
1993/// let some_vec = vec![12, 4, 6, 10, 8];
1994/// assert_that!(some_vec).contains(12);
1995///
1996/// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
1997/// assert_that!(some_btree_map).contains(('b', 0));
1998/// ```
1999pub trait AssertIteratorContains<'a, U, E, R> {
2000    /// Verifies that the actual collection/iterator contains the expected
2001    /// value.
2002    ///
2003    /// # Examples
2004    ///
2005    /// ```
2006    /// use asserting::prelude::*;
2007    /// use std::collections::BTreeMap;
2008    ///
2009    /// let some_array = [1, 3, 5, 7];
2010    /// assert_that!(some_array).contains(5);
2011    ///
2012    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2013    /// assert_that!(some_slice).contains(&'X');
2014    ///
2015    /// let some_vec = vec![12, 4, 6, 10, 8];
2016    /// assert_that!(some_vec).contains(12);
2017    ///
2018    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2019    /// assert_that!(some_btree_map).contains(('b', 0));
2020    /// ```
2021    #[track_caller]
2022    fn contains(self, element: E) -> Spec<'a, U, R>;
2023}
2024
2025/// Assert values in a collection.
2026///
2027/// These assertions do not rely on the order in which the collection iterates
2028/// over its values. They are implemented for any iterator over items that
2029/// implement `PartialEq<E>` with `E` being the type of the items in the
2030/// expected collection or iterator.
2031pub trait AssertIteratorContainsInAnyOrder<'a, S, E, R> {
2032    /// Verifies that the actual collection/iterator contains exactly the given
2033    /// values and nothing else in any order.
2034    ///
2035    /// # Examples
2036    ///
2037    /// ```
2038    /// use asserting::prelude::*;
2039    /// use std::collections::BTreeMap;
2040    ///
2041    /// let some_array = [1, 3, 5, 7];
2042    /// assert_that!(some_array).contains_exactly_in_any_order([3, 1, 5, 7]);
2043    ///
2044    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2045    /// assert_that!(some_slice).contains_exactly_in_any_order(&['X', 'k', 'b', 'G']);
2046    ///
2047    /// let some_vec = vec![12, 4, 6, 10, 8];
2048    /// assert_that!(some_vec).contains_exactly_in_any_order([8, 10, 6, 4, 12]);
2049    ///
2050    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2051    /// assert_that!(some_btree_map).contains_exactly_in_any_order([('b', 0), ('a', 3), ('c', 8)]);
2052    /// ```
2053    #[track_caller]
2054    fn contains_exactly_in_any_order(self, expected: E) -> Spec<'a, S, R>;
2055
2056    /// Verifies that the actual collection/iterator contains at least one of
2057    /// the given values.
2058    ///
2059    /// # Examples
2060    ///
2061    /// ```
2062    /// use asserting::prelude::*;
2063    /// use std::collections::BTreeMap;
2064    ///
2065    /// let some_array = [1, 3, 5, 7];
2066    /// assert_that!(some_array).contains_any_of([2, 3, 4]);
2067    ///
2068    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2069    /// assert_that!(some_slice).contains_any_of(&['a', 'b', 'c', 'd']);
2070    ///
2071    /// let some_vec = vec![12, 4, 6, 10, 8];
2072    /// assert_that!(some_vec).contains_any_of([1, 2, 3, 4, 5]);
2073    ///
2074    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2075    /// assert_that!(some_btree_map).contains_any_of([('x', 2), ('a', 3), ('y', 7)]);
2076    /// ```
2077    #[track_caller]
2078    fn contains_any_of(self, expected: E) -> Spec<'a, S, R>;
2079
2080    /// Verifies that the actual collection/iterator contains the given values
2081    /// in any order.
2082    ///
2083    /// The collection/iterator may contain more values than the given ones, but
2084    /// at least all the specified ones.
2085    ///
2086    /// # Examples
2087    ///
2088    /// ```
2089    /// use asserting::prelude::*;
2090    /// use std::collections::BTreeMap;
2091    ///
2092    /// let some_array = [1, 3, 5, 7];
2093    /// assert_that!(some_array).contains_all_of([3, 1, 5]);
2094    ///
2095    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2096    /// assert_that!(some_slice).contains_all_of(&['k', 'b']);
2097    ///
2098    /// let some_vec = vec![12, 4, 6, 10, 8];
2099    /// assert_that!(some_vec).contains_all_of([4, 6, 10, 12]);
2100    ///
2101    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2102    /// assert_that!(some_btree_map).contains_all_of([('a', 3), ('b', 0)]);
2103    /// ```
2104    #[track_caller]
2105    fn contains_all_of(self, expected: E) -> Spec<'a, S, R>;
2106
2107    /// Verifies that the actual collection/iterator contains only the given
2108    /// values and nothing else in any order and ignoring duplicates.
2109    ///
2110    /// The collection may contain fewer values than the expected ones.
2111    ///
2112    /// # Examples
2113    ///
2114    /// ```
2115    /// use asserting::prelude::*;
2116    /// use std::collections::BTreeMap;
2117    ///
2118    /// let some_array = [1, 3, 5, 7];
2119    /// assert_that!(some_array).contains_only([0, 5, 3, 1, 7, 9]);
2120    ///
2121    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2122    /// assert_that!(some_slice).contains_only(&['X', 'a', 'k', 'b', 'G', 'A']);
2123    ///
2124    /// let some_vec = vec![12, 4, 6, 10, 8];
2125    /// assert_that!(some_vec).contains_only([2, 4, 6, 8, 10, 12, 14, 0]);
2126    ///
2127    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2128    /// assert_that!(some_btree_map).contains_only([('a', 3), ('b', 0), ('c', 8), ('d', 4)]);
2129    /// ```
2130    #[track_caller]
2131    fn contains_only(self, expected: E) -> Spec<'a, S, R>;
2132
2133    /// Verifies that the actual collection/iterator contains only the given
2134    /// values in any order and each of them only once.
2135    ///
2136    /// The collection may contain fewer values than the expected ones.
2137    ///
2138    /// # Examples
2139    ///
2140    /// ```
2141    /// use asserting::prelude::*;
2142    /// use std::collections::BTreeMap;
2143    ///
2144    /// let some_array = [1, 3, 5, 7];
2145    /// assert_that!(some_array).contains_only_once([0, 1, 3, 5, 7, 9]);
2146    ///
2147    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2148    /// assert_that!(some_slice).contains_only_once(&['a', 'b', 'X', 'k', 'G']);
2149    ///
2150    /// let some_vec = vec![12, 4, 6, 10, 8];
2151    /// assert_that!(some_vec).contains_only_once([4, 6, 8, 10, 12, 15, 20]);
2152    /// ```
2153    #[track_caller]
2154    fn contains_only_once(self, expected: E) -> Spec<'a, S, R>;
2155}
2156
2157/// Assert values in an ordered collection.
2158///
2159/// These assertions are applicable to collections which iterate over their
2160/// values in a defined order.
2161pub trait AssertIteratorContainsInOrder<'a, S, E, R> {
2162    /// Verifies that the actual collection/iterator contains exactly the given
2163    /// values and nothing else in the given order.
2164    ///
2165    /// # Examples
2166    ///
2167    /// ```
2168    /// use asserting::prelude::*;
2169    /// use std::collections::BTreeMap;
2170    ///
2171    /// let some_array = [1, 3, 5, 7];
2172    /// assert_that!(some_array).contains_exactly([1, 3, 5, 7]);
2173    ///
2174    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2175    /// assert_that!(some_slice).contains_exactly(&['b', 'X', 'k', 'G']);
2176    ///
2177    /// let some_vec = vec![12, 4, 6, 10, 8];
2178    /// assert_that!(some_vec).contains_exactly([12, 4, 6, 10, 8]);
2179    ///
2180    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2181    /// assert_that!(some_btree_map).contains_exactly([('a', 3), ('b', 0), ('c', 8)]);
2182    /// ```
2183    #[track_caller]
2184    fn contains_exactly(self, expected: E) -> Spec<'a, S, R>;
2185
2186    /// Verifies that the actual collection/iterator contains the given sequence
2187    /// of values in the given order and without extra values between the
2188    /// sequence values.
2189    ///
2190    /// May contain more values as in the given sequence before and after the
2191    /// sequence.
2192    ///
2193    /// # Examples
2194    ///
2195    /// ```
2196    /// use asserting::prelude::*;
2197    /// use std::collections::BTreeMap;
2198    ///
2199    /// let some_array = [1, 3, 5, 7, 9];
2200    /// assert_that!(some_array).contains_sequence([3, 5, 7]);
2201    ///
2202    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2203    /// assert_that!(some_slice).contains_sequence(&['b', 'X']);
2204    ///
2205    /// let some_vec = vec![12, 4, 6, 10, 8];
2206    /// assert_that!(some_vec).contains_sequence([6, 10, 8]);
2207    ///
2208    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2209    /// assert_that!(some_btree_map).contains_sequence([('a', 3), ('b', 0), ('c', 8)]);
2210    /// ```
2211    #[track_caller]
2212    fn contains_sequence(self, expected: E) -> Spec<'a, S, R>;
2213
2214    /// Verifies that the actual collection/iterator contains all the given
2215    /// values and in the given order, possibly with other values between them.
2216    ///
2217    /// # Examples
2218    ///
2219    /// ```
2220    /// use asserting::prelude::*;
2221    /// use std::collections::BTreeMap;
2222    ///
2223    /// let some_array = [1, 3, 5, 7, 9];
2224    /// assert_that!(some_array).contains_all_in_order([3, 5, 9]);
2225    ///
2226    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2227    /// assert_that!(some_slice).contains_all_in_order(&['b', 'G']);
2228    ///
2229    /// let some_vec = vec![12, 4, 6, 10, 8];
2230    /// assert_that!(some_vec).contains_all_in_order([12, 4, 10, 8]);
2231    ///
2232    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2233    /// assert_that!(some_btree_map).contains_all_in_order([('a', 3), ('c', 8)]);
2234    /// ```
2235    #[track_caller]
2236    fn contains_all_in_order(self, expected: E) -> Spec<'a, S, R>;
2237
2238    /// Verifies that the actual collection/iterator contains the given values
2239    /// as the first elements in order.
2240    ///
2241    /// # Examples
2242    ///
2243    /// ```
2244    /// use asserting::prelude::*;
2245    /// use std::collections::BTreeMap;
2246    ///
2247    /// let some_array = [1, 3, 5, 7];
2248    /// assert_that!(some_array).starts_with([1, 3, 5]);
2249    ///
2250    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2251    /// assert_that!(some_slice).starts_with(&['b', 'X']);
2252    ///
2253    /// let some_vec = vec![12, 4, 6, 10, 8];
2254    /// assert_that!(some_vec).starts_with([12, 4, 6]);
2255    ///
2256    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2257    /// assert_that!(some_btree_map).starts_with([('a', 3), ('b', 0)]);
2258    /// ```
2259    #[track_caller]
2260    fn starts_with(self, expected: E) -> Spec<'a, S, R>;
2261
2262    /// Verifies that the actual collection/iterator contains the given values
2263    /// as the last elements in order.
2264    ///
2265    /// # Examples
2266    ///
2267    /// ```
2268    /// use asserting::prelude::*;
2269    /// use std::collections::BTreeMap;
2270    ///
2271    /// let some_array = [1, 3, 5, 7];
2272    /// assert_that!(some_array).ends_with([3, 5, 7]);
2273    ///
2274    /// let some_slice = &['b', 'X', 'k', 'G'][..];
2275    /// assert_that!(some_slice).ends_with(&['k', 'G']);
2276    ///
2277    /// let some_vec = vec![12, 4, 6, 10, 8];
2278    /// assert_that!(some_vec).ends_with([10, 8]);
2279    ///
2280    /// let some_btree_map = BTreeMap::from_iter([('a', 3), ('b', 0), ('c', 8)]);
2281    /// assert_that!(some_btree_map).ends_with([('b', 0), ('c', 8)]);
2282    /// ```
2283    #[track_caller]
2284    fn ends_with(self, expected: E) -> Spec<'a, S, R>;
2285}
2286
2287/// Assert the order of the values within a collection.
2288///
2289/// These assertions are applicable to ordered collections only.
2290pub trait AssertIsSorted {
2291    /// Verifies that the actual collection is sorted in ascending order.
2292    #[track_caller]
2293    fn is_sorted_ascending(self) -> Self;
2294
2295    /// Verifies that the actual collection is sorted in descending order.
2296    #[track_caller]
2297    fn is_sorted_descending(self) -> Self;
2298}
2299
2300/// Assert that the code under test panics, panics with a certain message or
2301/// does not panic.
2302///
2303/// # Examples
2304///
2305/// ```
2306/// use asserting::prelude::*;
2307///
2308/// fn do_something(input: &str) {
2309///     if input.is_empty() {
2310///         panic!("input is empty");
2311///     }
2312/// }
2313///
2314/// assert_that_code!(|| {
2315///     do_something("correct input");
2316/// }).does_not_panic();
2317///
2318/// assert_that_code!(|| {
2319///     do_something("");
2320/// }).panics();
2321///
2322/// assert_that_code!(|| {
2323///     do_something("");
2324/// }).panics_with_message("input is empty");
2325/// ```
2326#[cfg(feature = "panic")]
2327#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
2328pub trait AssertCodePanics<'a, R> {
2329    /// Verifies that the actual code under test does not panic.
2330    ///
2331    /// # Example
2332    ///
2333    /// ```
2334    /// use asserting::prelude::*;
2335    ///
2336    /// fn do_something(input: &str) {
2337    ///     if input.is_empty() {
2338    ///         panic!("input is empty");
2339    ///     }
2340    /// }
2341    ///
2342    /// assert_that_code!(|| {
2343    ///     do_something("correct input");
2344    /// }).does_not_panic();
2345    /// ```
2346    #[track_caller]
2347    fn does_not_panic(self) -> Spec<'a, (), R>;
2348
2349    /// Verifies that the actual code under test panics with any message.
2350    ///
2351    /// # Example
2352    ///
2353    /// ```
2354    /// use asserting::prelude::*;
2355    ///
2356    /// fn do_something(input: &str) {
2357    ///     if input.is_empty() {
2358    ///         panic!("input is empty");
2359    ///     }
2360    /// }
2361    ///
2362    /// assert_that_code!(|| {
2363    ///     do_something("");
2364    /// }).panics();
2365    /// ```
2366    #[track_caller]
2367    fn panics(self) -> Spec<'a, (), R>;
2368
2369    /// Verifies that the actual code under test panics with the given
2370    /// message.
2371    ///
2372    /// # Example
2373    ///
2374    /// ```
2375    /// use asserting::prelude::*;
2376    ///
2377    /// fn do_something(input: &str) {
2378    ///     if input.is_empty() {
2379    ///         panic!("input is empty");
2380    ///     }
2381    /// }
2382    ///
2383    /// assert_that_code!(|| {
2384    ///     do_something("");
2385    /// }).panics_with_message("input is empty");
2386    /// ```
2387    #[track_caller]
2388    fn panics_with_message(self, message: impl Into<String>) -> Spec<'a, (), R>;
2389}
2390
2391/// Assertions for the keys of a map.
2392///
2393/// # Examples
2394///
2395/// ```
2396/// # #[cfg(not(feature = "std"))]
2397/// # fn main() {}
2398/// # #[cfg(feature = "std")]
2399/// # fn main() {
2400/// use asserting::prelude::*;
2401/// use std::collections::HashMap;
2402///
2403/// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2404///
2405/// assert_that!(&subject).contains_key(5);
2406/// assert_that!(&subject).does_not_contain_key(3);
2407/// assert_that!(&subject).contains_keys([4, 8]);
2408/// assert_that!(&subject).does_not_contain_keys([3, 2, 7]);
2409/// assert_that!(&subject).contains_exactly_keys([4, 1, 5, 8]);
2410/// # }
2411/// ```
2412///
2413/// ```
2414/// use asserting::prelude::*;
2415/// use hashbrown::HashMap;
2416///
2417/// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2418///
2419/// assert_that!(&subject).contains_key(4);
2420/// assert_that!(&subject).does_not_contain_key(7);
2421/// assert_that!(&subject).contains_keys([1, 5]);
2422/// assert_that!(&subject).does_not_contain_keys([2, 7, 6]);
2423/// assert_that!(&subject).contains_exactly_keys([1, 4, 5, 8]);
2424/// ```
2425///
2426/// ```
2427/// # #[cfg(not(feature = "std"))]
2428/// # fn main() {}
2429/// # #[cfg(feature = "std")]
2430/// # fn main() {
2431/// use asserting::prelude::*;
2432/// use std::collections::BTreeMap;
2433///
2434/// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2435///
2436/// assert_that!(&subject).contains_key(4);
2437/// assert_that!(&subject).does_not_contain_key(2);
2438/// assert_that!(&subject).contains_keys([1, 4, 8]);
2439/// assert_that!(&subject).does_not_contain_keys([2, 3, 6]);
2440/// assert_that!(&subject).contains_exactly_keys([4, 5, 8, 1]);
2441/// # }
2442/// ```
2443pub trait AssertMapContainsKey<E> {
2444    /// Verify that the actual map contains a mapping for the given key.
2445    ///
2446    /// # Examples
2447    ///
2448    /// ```
2449    /// # #[cfg(not(feature = "std"))]
2450    /// # fn main() {}
2451    /// # #[cfg(feature = "std")]
2452    /// # fn main() {
2453    /// use asserting::prelude::*;
2454    /// use std::collections::HashMap;
2455    ///
2456    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2457    ///
2458    /// assert_that!(&subject).contains_key(5);
2459    /// assert_that!(subject).contains_key(1);
2460    /// # }
2461    /// ```
2462    ///
2463    /// ```
2464    /// use asserting::prelude::*;
2465    /// use hashbrown::HashMap;
2466    ///
2467    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2468    ///
2469    /// assert_that!(&subject).contains_key(4);
2470    /// assert_that!(subject).contains_key(8);
2471    /// ```
2472    ///
2473    /// ```
2474    /// # #[cfg(not(feature = "std"))]
2475    /// # fn main() {}
2476    /// # #[cfg(feature = "std")]
2477    /// # fn main() {
2478    /// use asserting::prelude::*;
2479    /// use std::collections::BTreeMap;
2480    ///
2481    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2482    ///
2483    /// assert_that!(&subject).contains_key(4);
2484    /// assert_that!(subject).contains_key(5);
2485    /// # }
2486    /// ```
2487    #[track_caller]
2488    fn contains_key(self, expected_key: E) -> Self;
2489
2490    /// Verify that the actual map does not contain any mapping for the given
2491    /// key.
2492    ///
2493    /// # Examples
2494    ///
2495    /// ```
2496    /// # #[cfg(not(feature = "std"))]
2497    /// # fn main() {}
2498    /// # #[cfg(feature = "std")]
2499    /// # fn main() {
2500    /// use asserting::prelude::*;
2501    /// use std::collections::HashMap;
2502    ///
2503    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2504    ///
2505    /// assert_that!(&subject).does_not_contain_key(2);
2506    /// assert_that!(subject).does_not_contain_key(3);
2507    /// # }
2508    /// ```
2509    ///
2510    /// ```
2511    /// use asserting::prelude::*;
2512    /// use hashbrown::HashMap;
2513    ///
2514    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2515    ///
2516    /// assert_that!(&subject).does_not_contain_key(6);
2517    /// assert_that!(subject).does_not_contain_key(7);
2518    /// ```
2519    ///
2520    /// ```
2521    /// # #[cfg(not(feature = "std"))]
2522    /// # fn main() {}
2523    /// # #[cfg(feature = "std")]
2524    /// # fn main() {
2525    /// use asserting::prelude::*;
2526    /// use std::collections::BTreeMap;
2527    ///
2528    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2529    ///
2530    /// assert_that!(&subject).does_not_contain_key(3);
2531    /// assert_that!(subject).does_not_contain_key(9);
2532    /// # }
2533    /// ```
2534    #[track_caller]
2535    fn does_not_contain_key(self, expected_key: E) -> Self;
2536
2537    /// Verify that the actual map contains a mapping for each of the given
2538    /// keys.
2539    ///
2540    /// The order of the keys is not relevant and duplicates are ignored.
2541    ///
2542    /// # Examples
2543    ///
2544    /// ```
2545    /// # #[cfg(not(feature = "std"))]
2546    /// # fn main() {}
2547    /// # #[cfg(feature = "std")]
2548    /// # fn main() {
2549    /// use asserting::prelude::*;
2550    /// use std::collections::HashMap;
2551    ///
2552    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2553    ///
2554    /// assert_that!(&subject).contains_keys([4, 5]);
2555    /// assert_that!(&subject).contains_keys([8, 1, 5]);
2556    /// assert_that!(&subject).contains_keys([8, 1, 1]);
2557    /// # }
2558    /// ```
2559    ///
2560    /// ```
2561    /// use asserting::prelude::*;
2562    /// use hashbrown::HashMap;
2563    ///
2564    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2565    ///
2566    /// assert_that!(&subject).contains_keys([1, 5]);
2567    /// assert_that!(&subject).contains_keys([8, 1, 4]);
2568    /// assert_that!(&subject).contains_keys([8, 4, 4]);
2569    /// ```
2570    ///
2571    /// ```
2572    /// # #[cfg(not(feature = "std"))]
2573    /// # fn main() {}
2574    /// # #[cfg(feature = "std")]
2575    /// # fn main() {
2576    /// use asserting::prelude::*;
2577    /// use std::collections::BTreeMap;
2578    ///
2579    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2580    ///
2581    /// assert_that!(&subject).contains_keys([1, 4, 5, 8]);
2582    /// assert_that!(&subject).contains_keys([5, 4, 8]);
2583    /// assert_that!(&subject).contains_keys([5, 5, 8]);
2584    /// # }
2585    /// ```
2586    #[track_caller]
2587    fn contains_keys(self, expected_keys: impl IntoIterator<Item = E>) -> Self;
2588
2589    /// Verify that the actual map does not contain any mapping for one of the
2590    /// given keys.
2591    ///
2592    /// The order of the keys is not relevant and duplicates are ignored.
2593    ///
2594    /// # Examples
2595    ///
2596    /// ```
2597    /// # #[cfg(not(feature = "std"))]
2598    /// # fn main() {}
2599    /// # #[cfg(feature = "std")]
2600    /// # fn main() {
2601    /// use asserting::prelude::*;
2602    /// use std::collections::HashMap;
2603    ///
2604    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2605    ///
2606    /// assert_that!(&subject).does_not_contain_keys([2, 3]);
2607    /// assert_that!(&subject).does_not_contain_keys([6, 3, 7]);
2608    /// assert_that!(&subject).does_not_contain_keys([3, 6, 3]);
2609    /// # }
2610    /// ```
2611    ///
2612    /// ```
2613    /// use asserting::prelude::*;
2614    /// use hashbrown::HashMap;
2615    ///
2616    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2617    ///
2618    /// assert_that!(&subject).does_not_contain_keys([6, 7]);
2619    /// assert_that!(&subject).does_not_contain_keys([3, 2, 6]);
2620    /// assert_that!(&subject).does_not_contain_keys([7, 2, 7]);
2621    /// ```
2622    ///
2623    /// ```
2624    /// # #[cfg(not(feature = "std"))]
2625    /// # fn main() {}
2626    /// # #[cfg(feature = "std")]
2627    /// # fn main() {
2628    /// use asserting::prelude::*;
2629    /// use std::collections::BTreeMap;
2630    ///
2631    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2632    ///
2633    /// assert_that!(&subject).does_not_contain_keys([2, 3, 6, 7]);
2634    /// assert_that!(&subject).does_not_contain_keys([7, 3, 6]);
2635    /// assert_that!(&subject).does_not_contain_keys([2, 2, 9]);
2636    /// # }
2637    /// ```
2638    #[track_caller]
2639    fn does_not_contain_keys(self, expected_keys: impl IntoIterator<Item = E>) -> Self;
2640
2641    /// Verifies that the actual map contains a mapping for each of the expected
2642    /// keys but no more.
2643    ///
2644    /// The order of the keys is not relevant and duplicates are ignored.
2645    ///
2646    /// # Examples
2647    ///
2648    /// ```
2649    /// # #[cfg(not(feature = "std"))]
2650    /// # fn main() {}
2651    /// # #[cfg(feature = "std")]
2652    /// # fn main() {
2653    /// use asserting::prelude::*;
2654    /// use std::collections::HashMap;
2655    ///
2656    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2657    ///
2658    /// assert_that!(&subject).contains_exactly_keys([4, 1, 5, 8]);
2659    /// assert_that!(&subject).contains_exactly_keys([1, 4, 5, 8]);
2660    /// assert_that!(&subject).contains_exactly_keys([1, 4, 5, 8, 8]);
2661    /// # }
2662    /// ```
2663    ///
2664    /// ```
2665    /// use asserting::prelude::*;
2666    /// use hashbrown::HashMap;
2667    ///
2668    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2669    ///
2670    /// assert_that!(&subject).contains_exactly_keys([4, 1, 5, 8]);
2671    /// assert_that!(&subject).contains_exactly_keys([1, 4, 5, 8]);
2672    /// assert_that!(&subject).contains_exactly_keys([1, 1, 4, 5, 8]);
2673    /// ```
2674    ///
2675    /// ```
2676    /// # #[cfg(not(feature = "std"))]
2677    /// # fn main() {}
2678    /// # #[cfg(feature = "std")]
2679    /// # fn main() {
2680    /// use asserting::prelude::*;
2681    /// use std::collections::BTreeMap;
2682    ///
2683    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2684    ///
2685    /// assert_that!(&subject).contains_exactly_keys([1, 4, 5, 8]);
2686    /// assert_that!(&subject).contains_exactly_keys([5, 4, 1, 8]);
2687    /// assert_that!(&subject).contains_exactly_keys([5, 4, 4, 1, 8]);
2688    /// # }
2689    /// ```
2690    #[track_caller]
2691    fn contains_exactly_keys(self, expected_keys: impl IntoIterator<Item = E>) -> Self;
2692}
2693
2694/// Assertions for the values of a map.
2695///
2696/// # Examples
2697///
2698/// ```
2699/// # #[cfg(not(feature = "std"))]
2700/// # fn main() {}
2701/// # #[cfg(feature = "std")]
2702/// # fn main() {
2703/// use asserting::prelude::*;
2704/// use std::collections::HashMap;
2705///
2706/// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2707///
2708/// assert_that!(&subject).contains_value("five");
2709/// assert_that!(&subject).does_not_contain_value("three");
2710/// assert_that!(&subject).contains_values(["four", "eight"]);
2711/// assert_that!(&subject).does_not_contain_values(["three", "two", "seven"]);
2712/// # }
2713/// ```
2714///
2715/// ```
2716/// use asserting::prelude::*;
2717/// use hashbrown::HashMap;
2718///
2719/// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2720///
2721/// assert_that!(&subject).contains_value("four");
2722/// assert_that!(&subject).does_not_contain_value("seven");
2723/// assert_that!(&subject).contains_values(["one", "five"]);
2724/// assert_that!(&subject).does_not_contain_values(["two", "seven", "six"]);
2725/// ```
2726///
2727/// ```
2728/// # #[cfg(not(feature = "std"))]
2729/// # fn main() {}
2730/// # #[cfg(feature = "std")]
2731/// # fn main() {
2732/// use asserting::prelude::*;
2733/// use std::collections::BTreeMap;
2734///
2735/// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2736///
2737/// assert_that!(&subject).contains_value("four");
2738/// assert_that!(&subject).does_not_contain_value("two");
2739/// assert_that!(&subject).contains_values(["four", "one", "eight"]);
2740/// assert_that!(&subject).does_not_contain_values(["two", "three", "six"]);
2741/// # }
2742/// ```
2743pub trait AssertMapContainsValue<E> {
2744    /// Verify that the actual map contains at least one mapping where the value
2745    /// is equal to the expected one.
2746    ///
2747    /// # Examples
2748    ///
2749    /// ```
2750    /// # #[cfg(not(feature = "std"))]
2751    /// # fn main() {}
2752    /// # #[cfg(feature = "std")]
2753    /// # fn main() {
2754    /// use asserting::prelude::*;
2755    /// use std::collections::HashMap;
2756    ///
2757    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2758    ///
2759    /// assert_that!(&subject).contains_value("five");
2760    /// assert_that!(subject).contains_value("one");
2761    /// # }
2762    /// ```
2763    ///
2764    /// ```
2765    /// use asserting::prelude::*;
2766    /// use hashbrown::HashMap;
2767    ///
2768    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2769    ///
2770    /// assert_that!(&subject).contains_value("one");
2771    /// assert_that!(subject).contains_value("eight");
2772    /// ```
2773    ///
2774    /// ```
2775    /// # #[cfg(not(feature = "std"))]
2776    /// # fn main() {}
2777    /// # #[cfg(feature = "std")]
2778    /// # fn main() {
2779    /// use asserting::prelude::*;
2780    /// use std::collections::BTreeMap;
2781    ///
2782    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2783    ///
2784    /// assert_that!(&subject).contains_value("four");
2785    /// assert_that!(subject).contains_value("five");
2786    /// # }
2787    /// ```
2788    #[track_caller]
2789    fn contains_value(self, expected_value: E) -> Self;
2790
2791    /// Verify that the actual map does not contain any mapping where the value
2792    /// is equal to the expected one.
2793    ///
2794    /// # Examples
2795    ///
2796    /// ```
2797    /// # #[cfg(not(feature = "std"))]
2798    /// # fn main() {}
2799    /// # #[cfg(feature = "std")]
2800    /// # fn main() {
2801    /// use asserting::prelude::*;
2802    /// use std::collections::HashMap;
2803    ///
2804    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2805    ///
2806    /// assert_that!(&subject).does_not_contain_value("two");
2807    /// assert_that!(subject).does_not_contain_value("three");
2808    /// # }
2809    /// ```
2810    ///
2811    /// ```
2812    /// use asserting::prelude::*;
2813    /// use hashbrown::HashMap;
2814    ///
2815    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2816    ///
2817    /// assert_that!(&subject).does_not_contain_value("six");
2818    /// assert_that!(subject).does_not_contain_value("seven");
2819    /// ```
2820    ///
2821    /// ```
2822    /// # #[cfg(not(feature = "std"))]
2823    /// # fn main() {}
2824    /// # #[cfg(feature = "std")]
2825    /// # fn main() {
2826    /// use asserting::prelude::*;
2827    /// use std::collections::BTreeMap;
2828    ///
2829    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2830    ///
2831    /// assert_that!(&subject).does_not_contain_value("three");
2832    /// assert_that!(subject).does_not_contain_value("nine");
2833    /// # }
2834    /// ```
2835    #[track_caller]
2836    fn does_not_contain_value(self, expected_value: E) -> Self;
2837
2838    /// Verify that the actual map contains at least one mapping for each of the
2839    /// given values, where the mapping contains one of the expected values.
2840    ///
2841    /// The order of the values is not relevant and duplicates are ignored.
2842    ///
2843    /// # Examples
2844    ///
2845    /// ```
2846    /// # #[cfg(not(feature = "std"))]
2847    /// # fn main() {}
2848    /// # #[cfg(feature = "std")]
2849    /// # fn main() {
2850    /// use asserting::prelude::*;
2851    /// use std::collections::HashMap;
2852    ///
2853    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2854    ///
2855    /// assert_that!(&subject).contains_values(["four", "five"]);
2856    /// assert_that!(&subject).contains_values(["eight", "one", "five"]);
2857    /// assert_that!(&subject).contains_values(["eight", "one", "one"]);
2858    /// # }
2859    /// ```
2860    ///
2861    /// ```
2862    /// use asserting::prelude::*;
2863    /// use hashbrown::HashMap;
2864    ///
2865    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2866    ///
2867    /// assert_that!(&subject).contains_values(["one", "five"]);
2868    /// assert_that!(&subject).contains_values(["eight", "one", "four"]);
2869    /// assert_that!(&subject).contains_values(["eight", "four", "four"]);
2870    /// ```
2871    ///
2872    /// ```
2873    /// # #[cfg(not(feature = "std"))]
2874    /// # fn main() {}
2875    /// # #[cfg(feature = "std")]
2876    /// # fn main() {
2877    /// use asserting::prelude::*;
2878    /// use std::collections::BTreeMap;
2879    ///
2880    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2881    ///
2882    /// assert_that!(&subject).contains_values(["one", "four", "five", "eight"]);
2883    /// assert_that!(&subject).contains_values(["five", "four", "eight"]);
2884    /// assert_that!(&subject).contains_values(["five", "five", "eight"]);
2885    /// # }
2886    /// ```
2887    #[track_caller]
2888    fn contains_values(self, expected_values: impl IntoIterator<Item = E>) -> Self;
2889
2890    /// Verify that the actual map does not contain any mapping where the value
2891    /// is one of the given values.
2892    ///
2893    /// The order of the values is not relevant and duplicates are ignored.
2894    ///
2895    /// # Examples
2896    ///
2897    /// ```
2898    /// # #[cfg(not(feature = "std"))]
2899    /// # fn main() {}
2900    /// # #[cfg(feature = "std")]
2901    /// # fn main() {
2902    /// use asserting::prelude::*;
2903    /// use std::collections::HashMap;
2904    ///
2905    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2906    ///
2907    /// assert_that!(&subject).does_not_contain_values(["two", "three"]);
2908    /// assert_that!(&subject).does_not_contain_values(["six", "three", "seven"]);
2909    /// assert_that!(&subject).does_not_contain_values(["three", "six", "three"]);
2910    /// # }
2911    /// ```
2912    ///
2913    /// ```
2914    /// use asserting::prelude::*;
2915    /// use hashbrown::HashMap;
2916    ///
2917    /// let subject: HashMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2918    ///
2919    /// assert_that!(&subject).does_not_contain_values(["six", "seven"]);
2920    /// assert_that!(&subject).does_not_contain_values(["three", "two", "six"]);
2921    /// assert_that!(&subject).does_not_contain_values(["seven", "two", "seven"]);
2922    /// ```
2923    ///
2924    /// ```
2925    /// # #[cfg(not(feature = "std"))]
2926    /// # fn main() {}
2927    /// # #[cfg(feature = "std")]
2928    /// # fn main() {
2929    /// use asserting::prelude::*;
2930    /// use std::collections::BTreeMap;
2931    ///
2932    /// let subject: BTreeMap<_, _> = [(4, "four"), (1, "one"), (5, "five"), (8, "eight")].into();
2933    ///
2934    /// assert_that!(&subject).does_not_contain_values(["two", "three", "six", "seven"]);
2935    /// assert_that!(&subject).does_not_contain_values(["seven", "three", "six"]);
2936    /// assert_that!(&subject).does_not_contain_values(["two", "two", "nine"]);
2937    /// # }
2938    /// ```
2939    #[track_caller]
2940    fn does_not_contain_values(self, expected_values: impl IntoIterator<Item = E>) -> Self;
2941}