1#![allow(missing_docs)]
4#![warn(clippy::return_self_not_must_use)]
5
6use crate::std::marker::PhantomData;
7use crate::std::{string::String, vec::Vec};
8use hashbrown::HashSet;
9#[cfg(feature = "regex")]
10use regex::Regex;
11
12pub fn not<E>(expectation: E) -> Not<E> {
27 Not(expectation)
28}
29
30#[must_use]
44pub struct Not<E>(pub E);
45
46pub fn all<A>(expectations: A) -> All<A::Output>
59where
60 A: IntoRec,
61{
62 All(expectations.into_rec())
63}
64
65#[must_use]
71pub struct All<E>(pub E);
72
73pub fn any<A>(expectations: A) -> Any<A::Output>
86where
87 A: IntoRec,
88{
89 Any(expectations.into_rec())
90}
91
92pub struct Any<E>(pub E);
98
99pub fn rec<E>(expectations: E) -> Rec<E> {
103 Rec::new(expectations)
104}
105
106#[must_use]
137pub struct Rec<E> {
138 pub expectation: E,
139 pub result: Option<bool>,
140}
141
142impl<E> Rec<E> {
143 pub fn new(expectation: E) -> Self {
145 Self {
146 expectation,
147 result: None,
148 }
149 }
150
151 pub fn is_success(&self) -> bool {
154 self.result.is_some_and(|r| r)
155 }
156
157 pub fn is_failure(&self) -> bool {
160 self.result.is_some_and(|r| !r)
161 }
162}
163
164pub trait IntoRec {
171 type Output;
173
174 fn into_rec(self) -> Self::Output;
180}
181
182pub fn satisfies<F>(predicate: F) -> Predicate<F> {
207 Predicate {
208 predicate,
209 message: None,
210 }
211}
212
213#[must_use]
214pub struct Predicate<F> {
215 pub predicate: F,
216 pub message: Option<String>,
217}
218
219impl<F> Predicate<F> {
220 pub fn with_message(mut self, message: impl Into<String>) -> Self {
222 self.message = Some(message.into());
223 self
224 }
225}
226
227pub fn is_true() -> IsTrue {
229 IsTrue
230}
231
232#[must_use]
233pub struct IsTrue;
234
235pub fn is_false() -> IsFalse {
237 IsFalse
238}
239
240#[must_use]
241pub struct IsFalse;
242
243pub fn is_equal_to<E>(expected: E) -> IsEqualTo<E> {
245 IsEqualTo { expected }
246}
247
248#[must_use]
249pub struct IsEqualTo<E> {
250 pub expected: E,
251}
252
253pub fn is_same_as<E>(expected: E) -> IsSameAs<E> {
255 IsSameAs { expected }
256}
257
258pub struct IsSameAs<E> {
259 pub expected: E,
260}
261
262pub fn is_close_to<E, M>(expected: E) -> IsCloseTo<E, M>
286where
287 M: Default,
288{
289 IsCloseTo {
290 expected,
291 margin: M::default(),
292 }
293}
294
295#[must_use]
296pub struct IsCloseTo<E, M> {
297 pub expected: E,
298 pub margin: M,
299}
300
301impl<E, M> IsCloseTo<E, M>
302where
303 M: Default,
304{
305 #[deprecated = "use the function [`is_close_to`] instead"]
306 pub fn new(expected: E) -> Self {
307 Self {
308 expected,
309 margin: M::default(),
310 }
311 }
312}
313
314impl<E, M> IsCloseTo<E, M> {
315 pub fn within_margin(mut self, margin: impl Into<M>) -> Self {
316 self.margin = margin.into();
317 self
318 }
319}
320
321pub fn is_less_than<E>(expected: E) -> IsLessThan<E> {
323 IsLessThan { expected }
324}
325
326#[must_use]
327pub struct IsLessThan<E> {
328 pub expected: E,
329}
330
331pub fn is_at_most<E>(expected: E) -> IsAtMost<E> {
333 IsAtMost { expected }
334}
335
336#[must_use]
337pub struct IsAtMost<E> {
338 pub expected: E,
339}
340
341pub fn is_greater_than<E>(expected: E) -> IsGreaterThan<E> {
343 IsGreaterThan { expected }
344}
345
346#[must_use]
347pub struct IsGreaterThan<E> {
348 pub expected: E,
349}
350
351pub fn is_at_least<E>(expected: E) -> IsAtLeast<E> {
353 IsAtLeast { expected }
354}
355
356#[must_use]
357pub struct IsAtLeast<E> {
358 pub expected: E,
359}
360
361pub fn is_before<E>(expected: E) -> IsBefore<E> {
363 IsBefore { expected }
364}
365
366#[must_use]
367pub struct IsBefore<E> {
368 pub expected: E,
369}
370
371pub fn is_after<E>(expected: E) -> IsAfter<E> {
373 IsAfter { expected }
374}
375
376#[must_use]
377pub struct IsAfter<E> {
378 pub expected: E,
379}
380
381pub fn is_between<E>(min: E, max: E) -> IsBetween<E> {
383 IsBetween { min, max }
384}
385
386#[must_use]
387pub struct IsBetween<E> {
388 pub min: E,
389 pub max: E,
390}
391
392pub fn is_in_range<R, E>(expected_range: R) -> IsInRange<R, E> {
394 IsInRange {
395 expected_range,
396 _element_type: PhantomData,
397 }
398}
399
400#[must_use]
401pub struct IsInRange<R, E> {
402 pub expected_range: R,
403 _element_type: PhantomData<E>,
404}
405
406impl<R, E> IsInRange<R, E> {
407 #[deprecated = "use the function [`is_in_range`] instead"]
408 pub fn new(expected_range: R) -> Self {
409 Self {
410 expected_range,
411 _element_type: PhantomData,
412 }
413 }
414}
415
416pub fn is_negative() -> IsNegative {
418 IsNegative
419}
420
421#[must_use]
422pub struct IsNegative;
423
424pub fn is_positive() -> IsPositive {
426 IsPositive
427}
428
429#[must_use]
430pub struct IsPositive;
431
432pub fn is_zero() -> IsZero {
434 IsZero
435}
436
437#[must_use]
438pub struct IsZero;
439
440pub fn is_one() -> IsOne {
442 IsOne
443}
444
445#[must_use]
446pub struct IsOne;
447
448pub fn is_finite() -> IsFinite {
450 IsFinite
451}
452
453#[must_use]
454pub struct IsFinite;
455
456pub fn is_infinite() -> IsInfinite {
458 IsInfinite
459}
460
461#[must_use]
462pub struct IsInfinite;
463
464pub fn is_a_number() -> IsANumber {
466 IsANumber
467}
468
469#[must_use]
470pub struct IsANumber;
471
472pub fn has_precision_of(expected_precision: u64) -> HasPrecisionOf {
474 HasPrecisionOf { expected_precision }
475}
476
477#[must_use]
478pub struct HasPrecisionOf {
479 pub expected_precision: u64,
480}
481
482pub fn has_scale_of(expected_scale: i64) -> HasScaleOf {
484 HasScaleOf { expected_scale }
485}
486
487#[must_use]
488pub struct HasScaleOf {
489 pub expected_scale: i64,
490}
491
492pub fn is_integer() -> IsInteger {
494 IsInteger
495}
496
497#[must_use]
498pub struct IsInteger;
499
500pub fn is_lower_case() -> IsLowerCase {
502 IsLowerCase
503}
504
505#[must_use]
506pub struct IsLowerCase;
507
508pub fn is_upper_case() -> IsUpperCase {
510 IsUpperCase
511}
512
513#[must_use]
514pub struct IsUpperCase;
515
516pub fn is_ascii() -> IsAscii {
518 IsAscii
519}
520
521#[must_use]
522pub struct IsAscii;
523
524pub fn is_alphabetic() -> IsAlphabetic {
526 IsAlphabetic
527}
528
529#[must_use]
530pub struct IsAlphabetic;
531
532pub fn is_alphanumeric() -> IsAlphanumeric {
534 IsAlphanumeric
535}
536
537#[must_use]
538pub struct IsAlphanumeric;
539
540pub fn is_control_char() -> IsControlChar {
542 IsControlChar
543}
544
545#[must_use]
546pub struct IsControlChar;
547
548pub fn is_digit(radix: u32) -> IsDigit {
550 IsDigit { radix }
551}
552
553#[must_use]
554pub struct IsDigit {
555 pub radix: u32,
556}
557
558pub fn is_whitespace() -> IsWhitespace {
560 IsWhitespace
561}
562
563#[must_use]
564pub struct IsWhitespace;
565
566pub fn is_some() -> IsSome {
568 IsSome
569}
570
571#[must_use]
572pub struct IsSome;
573
574pub fn is_none() -> IsNone {
576 IsNone
577}
578
579#[must_use]
580pub struct IsNone;
581
582pub fn has_value<E>(expected: E) -> HasValue<E> {
584 HasValue { expected }
585}
586
587#[must_use]
588pub struct HasValue<E> {
589 pub expected: E,
590}
591
592pub fn is_ok() -> IsOk {
594 IsOk
595}
596
597#[must_use]
598pub struct IsOk;
599
600pub fn is_err() -> IsErr {
602 IsErr
603}
604
605#[must_use]
606pub struct IsErr;
607
608pub fn has_error<E>(expected: E) -> HasError<E> {
610 HasError { expected }
611}
612
613#[must_use]
614pub struct HasError<E> {
615 pub expected: E,
616}
617
618pub fn error_has_source() -> ErrorHasSource {
620 ErrorHasSource
621}
622
623#[must_use]
624pub struct ErrorHasSource;
625
626pub fn error_has_source_message(
628 expected_source_message: impl Into<String>,
629) -> ErrorHasSourceMessage {
630 ErrorHasSourceMessage {
631 expected_source_message: expected_source_message.into(),
632 }
633}
634
635#[must_use]
636pub struct ErrorHasSourceMessage {
637 pub expected_source_message: String,
638}
639
640pub fn has_debug_message<E>(expected: E) -> HasDebugMessage<E> {
642 HasDebugMessage { expected }
643}
644
645pub struct HasDebugMessage<E> {
646 pub expected: E,
647}
648
649pub fn has_display_message<E>(expected: E) -> HasDisplayMessage<E> {
651 HasDisplayMessage { expected }
652}
653
654pub struct HasDisplayMessage<E> {
655 pub expected: E,
656}
657
658pub fn is_empty() -> IsEmpty {
660 IsEmpty
661}
662
663#[must_use]
664pub struct IsEmpty;
665
666pub fn has_length<E>(expected_length: E) -> HasLength<E> {
668 HasLength { expected_length }
669}
670
671#[must_use]
672pub struct HasLength<E> {
673 pub expected_length: E,
674}
675
676pub fn has_length_in_range<R, E>(expected_range: R) -> HasLengthInRange<R, E> {
678 HasLengthInRange {
679 expected_range,
680 _element_type: PhantomData,
681 }
682}
683
684#[must_use]
685pub struct HasLengthInRange<R, E> {
686 pub expected_range: R,
687 _element_type: PhantomData<E>,
688}
689
690impl<R, E> HasLengthInRange<R, E> {
691 #[deprecated = "use the function [`has_length_in_range`] instead"]
692 pub fn new(expected_range: R) -> Self {
693 Self {
694 expected_range,
695 _element_type: PhantomData,
696 }
697 }
698}
699
700pub fn has_length_less_than<E>(expected_length: E) -> HasLengthLessThan<E> {
702 HasLengthLessThan { expected_length }
703}
704
705#[must_use]
706pub struct HasLengthLessThan<E> {
707 pub expected_length: E,
708}
709
710pub fn has_length_greater_than<E>(expected_length: E) -> HasLengthGreaterThan<E> {
712 HasLengthGreaterThan { expected_length }
713}
714
715#[must_use]
716pub struct HasLengthGreaterThan<E> {
717 pub expected_length: E,
718}
719
720pub fn has_at_most_length<E>(expected_length: E) -> HasAtMostLength<E> {
722 HasAtMostLength { expected_length }
723}
724
725#[must_use]
726pub struct HasAtMostLength<E> {
727 pub expected_length: E,
728}
729
730pub fn has_at_least_length<E>(expected_length: E) -> HasAtLeastLength<E> {
732 HasAtLeastLength { expected_length }
733}
734
735#[must_use]
736pub struct HasAtLeastLength<E> {
737 pub expected_length: E,
738}
739
740pub fn has_char_count<E>(expected_char_count: E) -> HasCharCount<E> {
742 HasCharCount {
743 expected_char_count,
744 }
745}
746
747#[must_use]
748pub struct HasCharCount<E> {
749 pub expected_char_count: E,
750}
751
752pub fn has_char_count_in_range<R, E>(expected_range: R) -> HasCharCountInRange<R, E> {
754 HasCharCountInRange {
755 expected_range,
756 _element_type: PhantomData,
757 }
758}
759
760#[must_use]
761pub struct HasCharCountInRange<R, E> {
762 pub expected_range: R,
763 _element_type: PhantomData<E>,
764}
765
766impl<R, E> HasCharCountInRange<R, E> {
767 #[deprecated = "use the function [`has_char_count_in_range`] instead"]
768 pub fn new(expected_range: R) -> Self {
769 Self {
770 expected_range,
771 _element_type: PhantomData,
772 }
773 }
774}
775
776pub fn has_char_count_less_than<E>(expected_char_count: E) -> HasCharCountLessThan<E> {
778 HasCharCountLessThan {
779 expected_char_count,
780 }
781}
782
783#[must_use]
784pub struct HasCharCountLessThan<E> {
785 pub expected_char_count: E,
786}
787
788pub fn has_char_count_greater_than<E>(expected_char_count: E) -> HasCharCountGreaterThan<E> {
790 HasCharCountGreaterThan {
791 expected_char_count,
792 }
793}
794
795#[must_use]
796pub struct HasCharCountGreaterThan<E> {
797 pub expected_char_count: E,
798}
799
800pub fn has_at_most_char_count<E>(expected_char_count: E) -> HasAtMostCharCount<E> {
802 HasAtMostCharCount {
803 expected_char_count,
804 }
805}
806
807#[must_use]
808pub struct HasAtMostCharCount<E> {
809 pub expected_char_count: E,
810}
811
812pub fn has_at_least_char_count<E>(expected_char_count: E) -> HasAtLeastCharCount<E> {
814 HasAtLeastCharCount {
815 expected_char_count,
816 }
817}
818
819#[must_use]
820pub struct HasAtLeastCharCount<E> {
821 pub expected_char_count: E,
822}
823
824pub fn string_contains<E>(expected: E) -> StringContains<E> {
826 StringContains { expected }
827}
828
829#[must_use]
830pub struct StringContains<E> {
831 pub expected: E,
832}
833
834pub fn string_contains_any_of<E>(expected: E) -> StringContainsAnyOf<E> {
836 StringContainsAnyOf { expected }
837}
838
839#[must_use]
840pub struct StringContainsAnyOf<E> {
841 pub expected: E,
842}
843
844pub fn string_starts_with<E>(expected: E) -> StringStartWith<E> {
846 StringStartWith { expected }
847}
848
849#[must_use]
850pub struct StringStartWith<E> {
851 pub expected: E,
852}
853
854pub fn string_ends_with<E>(expected: E) -> StringEndsWith<E> {
856 StringEndsWith { expected }
857}
858
859#[must_use]
860pub struct StringEndsWith<E> {
861 pub expected: E,
862}
863
864#[cfg(feature = "regex")]
870#[cfg_attr(docsrs, doc(cfg(feature = "regex")))]
871pub fn string_matches(regex_pattern: &str) -> StringMatches<'_> {
872 let regex = Regex::new(regex_pattern)
873 .unwrap_or_else(|err| panic!("failed to match string with regex: {err}"));
874 StringMatches {
875 pattern: regex_pattern,
876 regex,
877 }
878}
879
880#[cfg(feature = "regex")]
881#[cfg_attr(docsrs, doc(cfg(feature = "regex")))]
882#[must_use]
883pub struct StringMatches<'a> {
884 pub pattern: &'a str,
885 pub regex: Regex,
886}
887
888#[cfg(feature = "regex")]
889#[cfg_attr(docsrs, doc(cfg(feature = "regex")))]
890impl<'a> StringMatches<'a> {
891 #[deprecated = "use the function [`string_matches`] instead"]
897 pub fn new(regex_pattern: &'a str) -> Self {
898 let regex = Regex::new(regex_pattern)
899 .unwrap_or_else(|err| panic!("failed to match string with regex: {err}"));
900 Self {
901 pattern: regex_pattern,
902 regex,
903 }
904 }
905}
906
907pub fn iterator_contains<E>(expected: E) -> IteratorContains<E> {
909 IteratorContains { expected }
910}
911
912#[must_use]
913pub struct IteratorContains<E> {
914 pub expected: E,
915}
916
917pub fn iterator_contains_exactly_in_any_order<E>(
919 expected: impl IntoIterator<Item = E>,
920) -> IteratorContainsExactlyInAnyOrder<E> {
921 IteratorContainsExactlyInAnyOrder {
922 expected: Vec::from_iter(expected),
923 missing: HashSet::new(),
924 extra: HashSet::new(),
925 }
926}
927
928#[must_use]
929pub struct IteratorContainsExactlyInAnyOrder<E> {
930 pub expected: Vec<E>,
931 pub missing: HashSet<usize>,
932 pub extra: HashSet<usize>,
933}
934
935impl<E> IteratorContainsExactlyInAnyOrder<E> {
936 #[deprecated = "use the function [`iterator_contains_exactly_in_any_order`] instead"]
937 pub fn new(expected: Vec<E>) -> Self {
938 Self {
939 expected,
940 missing: HashSet::new(),
941 extra: HashSet::new(),
942 }
943 }
944}
945
946pub fn iterator_contains_any_of<E>(
948 expected: impl IntoIterator<Item = E>,
949) -> IteratorContainsAnyOf<E> {
950 IteratorContainsAnyOf {
951 expected: Vec::from_iter(expected),
952 }
953}
954
955#[must_use]
956pub struct IteratorContainsAnyOf<E> {
957 pub expected: Vec<E>,
958}
959
960pub fn iterator_contains_all_of<E>(
962 expected: impl IntoIterator<Item = E>,
963) -> IteratorContainsAllOf<E> {
964 IteratorContainsAllOf {
965 expected: Vec::from_iter(expected),
966 missing: HashSet::new(),
967 }
968}
969
970#[must_use]
971pub struct IteratorContainsAllOf<E> {
972 pub expected: Vec<E>,
973 pub missing: HashSet<usize>,
974}
975
976impl<E> IteratorContainsAllOf<E> {
977 #[deprecated = "use the function [`iterator_contains_all_of`] instead"]
978 pub fn new(expected: Vec<E>) -> Self {
979 Self {
980 expected,
981 missing: HashSet::new(),
982 }
983 }
984}
985
986pub fn iterator_contains_only<E>(expected: impl IntoIterator<Item = E>) -> IteratorContainsOnly<E> {
988 IteratorContainsOnly {
989 expected: Vec::from_iter(expected),
990 extra: HashSet::new(),
991 }
992}
993
994#[must_use]
995pub struct IteratorContainsOnly<E> {
996 pub expected: Vec<E>,
997 pub extra: HashSet<usize>,
998}
999
1000impl<E> IteratorContainsOnly<E> {
1001 #[deprecated = "use the function [`iterator_contains_only`] instead"]
1002 pub fn new(expected: Vec<E>) -> Self {
1003 Self {
1004 expected,
1005 extra: HashSet::new(),
1006 }
1007 }
1008}
1009
1010pub fn iterator_contains_only_once<E>(
1012 expected: impl IntoIterator<Item = E>,
1013) -> IteratorContainsOnlyOnce<E> {
1014 IteratorContainsOnlyOnce {
1015 expected: Vec::from_iter(expected),
1016 extra: HashSet::new(),
1017 duplicates: HashSet::new(),
1018 }
1019}
1020
1021#[must_use]
1022pub struct IteratorContainsOnlyOnce<E> {
1023 pub expected: Vec<E>,
1024 pub extra: HashSet<usize>,
1025 pub duplicates: HashSet<usize>,
1026}
1027
1028impl<E> IteratorContainsOnlyOnce<E> {
1029 #[deprecated = "use the function [`iterator_contains_only_once`] instead"]
1030 pub fn new(expected: Vec<E>) -> Self {
1031 Self {
1032 expected,
1033 extra: HashSet::new(),
1034 duplicates: HashSet::new(),
1035 }
1036 }
1037}
1038
1039pub fn iterator_contains_exactly<E>(
1041 expected: impl IntoIterator<Item = E>,
1042) -> IteratorContainsExactly<E> {
1043 IteratorContainsExactly {
1044 expected: Vec::from_iter(expected),
1045 missing: HashSet::new(),
1046 extra: HashSet::new(),
1047 out_of_order: HashSet::new(),
1048 }
1049}
1050
1051#[must_use]
1052pub struct IteratorContainsExactly<E> {
1053 pub expected: Vec<E>,
1054 pub missing: HashSet<usize>,
1055 pub extra: HashSet<usize>,
1056 pub out_of_order: HashSet<usize>,
1057}
1058
1059impl<E> IteratorContainsExactly<E> {
1060 #[deprecated = "use the function [`iterator_contains_exactly`] instead"]
1061 pub fn new(expected: Vec<E>) -> Self {
1062 Self {
1063 expected,
1064 missing: HashSet::new(),
1065 extra: HashSet::new(),
1066 out_of_order: HashSet::new(),
1067 }
1068 }
1069}
1070
1071pub fn iterator_contains_sequence<E>(
1073 expected: impl IntoIterator<Item = E>,
1074) -> IteratorContainsSequence<E> {
1075 IteratorContainsSequence {
1076 expected: Vec::from_iter(expected),
1077 missing: HashSet::new(),
1078 extra: HashSet::new(),
1079 }
1080}
1081
1082#[must_use]
1083pub struct IteratorContainsSequence<E> {
1084 pub expected: Vec<E>,
1085 pub missing: HashSet<usize>,
1086 pub extra: HashSet<usize>,
1087}
1088
1089impl<E> IteratorContainsSequence<E> {
1090 #[deprecated = "use the function [`iterator_contains_sequence`] instead"]
1091 pub fn new(expected: Vec<E>) -> Self {
1092 Self {
1093 expected,
1094 missing: HashSet::new(),
1095 extra: HashSet::new(),
1096 }
1097 }
1098}
1099
1100pub fn iterator_contains_all_in_order<E>(
1102 expected: impl IntoIterator<Item = E>,
1103) -> IteratorContainsAllInOrder<E> {
1104 IteratorContainsAllInOrder {
1105 expected: Vec::from_iter(expected),
1106 missing: HashSet::new(),
1107 }
1108}
1109
1110#[must_use]
1111pub struct IteratorContainsAllInOrder<E> {
1112 pub expected: Vec<E>,
1113 pub missing: HashSet<usize>,
1114}
1115
1116impl<E> IteratorContainsAllInOrder<E> {
1117 #[deprecated = "use the function [`iterator_contains_all_in_order`] instead"]
1118 pub fn new(expected: Vec<E>) -> Self {
1119 Self {
1120 expected,
1121 missing: HashSet::new(),
1122 }
1123 }
1124}
1125
1126pub fn iterator_starts_with<E>(expected: impl IntoIterator<Item = E>) -> IteratorStartsWith<E> {
1128 IteratorStartsWith {
1129 expected: Vec::from_iter(expected),
1130 missing: HashSet::new(),
1131 extra: HashSet::new(),
1132 }
1133}
1134
1135#[must_use]
1136pub struct IteratorStartsWith<E> {
1137 pub expected: Vec<E>,
1138 pub missing: HashSet<usize>,
1139 pub extra: HashSet<usize>,
1140}
1141
1142impl<E> IteratorStartsWith<E> {
1143 #[deprecated = "use the function [`iterator_starts_with`] instead"]
1144 pub fn new(expected: Vec<E>) -> Self {
1145 Self {
1146 expected,
1147 missing: HashSet::new(),
1148 extra: HashSet::new(),
1149 }
1150 }
1151}
1152
1153pub fn iterator_ends_with<E>(expected: impl IntoIterator<Item = E>) -> IteratorEndsWith<E> {
1155 IteratorEndsWith {
1156 expected: Vec::from_iter(expected),
1157 missing: HashSet::new(),
1158 extra: HashSet::new(),
1159 }
1160}
1161
1162#[must_use]
1163pub struct IteratorEndsWith<E> {
1164 pub expected: Vec<E>,
1165 pub missing: HashSet<usize>,
1166 pub extra: HashSet<usize>,
1167}
1168
1169impl<E> IteratorEndsWith<E> {
1170 #[deprecated = "use the function [`iterator_ends_with`] instead"]
1171 pub fn new(expected: Vec<E>) -> Self {
1172 Self {
1173 expected,
1174 missing: HashSet::new(),
1175 extra: HashSet::new(),
1176 }
1177 }
1178}
1179
1180pub fn has_single_element() -> HasSingleElement {
1181 HasSingleElement
1182}
1183
1184#[must_use]
1185pub struct HasSingleElement;
1186
1187pub fn has_at_least_number_of_elements(
1188 expected_number_of_elements: usize,
1189) -> HasAtLeastNumberOfElements {
1190 HasAtLeastNumberOfElements {
1191 expected_number_of_elements,
1192 }
1193}
1194
1195#[must_use]
1196pub struct HasAtLeastNumberOfElements {
1197 pub expected_number_of_elements: usize,
1198}
1199
1200pub fn any_satisfies<P>(predicate: P) -> AnySatisfies<P> {
1201 AnySatisfies { predicate }
1202}
1203
1204#[must_use]
1205pub struct AnySatisfies<P> {
1206 pub predicate: P,
1207}
1208
1209pub fn all_satisfy<P>(predicate: P) -> AllSatisfy<P> {
1210 AllSatisfy {
1211 predicate,
1212 failing: HashSet::new(),
1213 }
1214}
1215
1216#[must_use]
1217pub struct AllSatisfy<P> {
1218 pub predicate: P,
1219 pub failing: HashSet<usize>,
1220}
1221
1222pub fn none_satisfies<P>(predicate: P) -> NoneSatisfies<P> {
1223 NoneSatisfies {
1224 predicate,
1225 failing: HashSet::new(),
1226 }
1227}
1228
1229#[must_use]
1230pub struct NoneSatisfies<P> {
1231 pub predicate: P,
1232 pub failing: HashSet<usize>,
1233}
1234
1235pub fn map_contains_key<E>(expected_key: E) -> MapContainsKey<E> {
1237 MapContainsKey { expected_key }
1238}
1239
1240#[must_use]
1241pub struct MapContainsKey<E> {
1242 pub expected_key: E,
1243}
1244
1245pub fn map_contains_value<E>(expected_value: E) -> MapContainsValue<E> {
1247 MapContainsValue { expected_value }
1248}
1249
1250#[must_use]
1251pub struct MapContainsValue<E> {
1252 pub expected_value: E,
1253}
1254
1255pub fn map_contains_keys<E>(expected_keys: impl IntoIterator<Item = E>) -> MapContainsKeys<E> {
1257 MapContainsKeys {
1258 expected_keys: Vec::from_iter(expected_keys),
1259 missing: HashSet::new(),
1260 }
1261}
1262
1263#[must_use]
1264pub struct MapContainsKeys<E> {
1265 pub expected_keys: Vec<E>,
1266 pub missing: HashSet<usize>,
1267}
1268
1269impl<E> MapContainsKeys<E> {
1270 #[deprecated = "use the function [`map_contains_keys`] instead"]
1271 pub fn new(expected_keys: impl IntoIterator<Item = E>) -> Self {
1272 Self {
1273 expected_keys: Vec::from_iter(expected_keys),
1274 missing: HashSet::new(),
1275 }
1276 }
1277}
1278
1279pub fn map_does_not_contain_keys<E>(
1281 expected_keys: impl IntoIterator<Item = E>,
1282) -> MapDoesNotContainKeys<E> {
1283 MapDoesNotContainKeys {
1284 expected_keys: Vec::from_iter(expected_keys),
1285 extra: HashSet::new(),
1286 }
1287}
1288
1289#[must_use]
1290pub struct MapDoesNotContainKeys<E> {
1291 pub expected_keys: Vec<E>,
1292 pub extra: HashSet<usize>,
1293}
1294
1295impl<E> MapDoesNotContainKeys<E> {
1296 #[deprecated = "use the function [`map_does_not_contain_keys`] instead"]
1297 pub fn new(expected_keys: impl IntoIterator<Item = E>) -> Self {
1298 Self {
1299 expected_keys: Vec::from_iter(expected_keys),
1300 extra: HashSet::new(),
1301 }
1302 }
1303}
1304
1305pub fn map_contains_values<E>(
1307 expected_values: impl IntoIterator<Item = E>,
1308) -> MapContainsValues<E> {
1309 MapContainsValues {
1310 expected_values: Vec::from_iter(expected_values),
1311 missing: HashSet::new(),
1312 }
1313}
1314
1315#[must_use]
1316pub struct MapContainsValues<E> {
1317 pub expected_values: Vec<E>,
1318 pub missing: HashSet<usize>,
1319}
1320
1321impl<E> MapContainsValues<E> {
1322 #[deprecated = "use the function [`map_contains_values`] instead"]
1323 pub fn new(expected_values: impl IntoIterator<Item = E>) -> Self {
1324 Self {
1325 expected_values: Vec::from_iter(expected_values),
1326 missing: HashSet::new(),
1327 }
1328 }
1329}
1330
1331pub fn map_does_not_contain_values<E>(
1333 expected_values: impl IntoIterator<Item = E>,
1334) -> MapDoesNotContainValues<E> {
1335 MapDoesNotContainValues {
1336 expected_values: Vec::from_iter(expected_values),
1337 extra: HashSet::new(),
1338 }
1339}
1340
1341#[must_use]
1342pub struct MapDoesNotContainValues<E> {
1343 pub expected_values: Vec<E>,
1344 pub extra: HashSet<usize>,
1345}
1346
1347impl<E> MapDoesNotContainValues<E> {
1348 #[deprecated = "use the function [`map_does_not_contain_values`] instead"]
1349 pub fn new(expected_values: impl IntoIterator<Item = E>) -> Self {
1350 Self {
1351 expected_values: Vec::from_iter(expected_values),
1352 extra: HashSet::new(),
1353 }
1354 }
1355}
1356
1357pub fn map_contains_exactly_keys<E>(
1359 expected_keys: impl IntoIterator<Item = E>,
1360) -> MapContainsExactlyKeys<E> {
1361 MapContainsExactlyKeys {
1362 expected_keys: Vec::from_iter(expected_keys),
1363 missing: HashSet::new(),
1364 extra: HashSet::new(),
1365 }
1366}
1367
1368#[must_use]
1369pub struct MapContainsExactlyKeys<E> {
1370 pub expected_keys: Vec<E>,
1371 pub missing: HashSet<usize>,
1372 pub extra: HashSet<usize>,
1373}
1374
1375impl<E> MapContainsExactlyKeys<E> {
1376 #[deprecated = "use the function [`map_contains_exactly_keys`] instead"]
1377 pub fn new(expected_keys: impl IntoIterator<Item = E>) -> Self {
1378 Self {
1379 expected_keys: Vec::from_iter(expected_keys),
1380 missing: HashSet::new(),
1381 extra: HashSet::new(),
1382 }
1383 }
1384}
1385
1386#[cfg(feature = "panic")]
1407#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
1408pub fn does_panic() -> DoesPanic {
1409 DoesPanic {
1410 expected_message: None,
1411 actual_message: None,
1412 }
1413}
1414
1415#[cfg(feature = "panic")]
1416#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
1417#[must_use]
1418pub struct DoesPanic {
1419 pub expected_message: Option<String>,
1420 pub actual_message: Option<String>,
1421}
1422
1423#[cfg(feature = "panic")]
1424impl DoesPanic {
1425 pub fn with_message(mut self, message: impl Into<String>) -> Self {
1426 self.expected_message = Some(message.into());
1427 self
1428 }
1429}
1430
1431#[cfg(feature = "panic")]
1433#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
1434pub fn does_not_panic() -> DoesNotPanic {
1435 DoesNotPanic {
1436 actual_message: None,
1437 }
1438}
1439
1440#[cfg(feature = "panic")]
1441#[cfg_attr(docsrs, doc(cfg(feature = "panic")))]
1442#[must_use]
1443pub struct DoesNotPanic {
1444 pub actual_message: Option<Box<dyn std::any::Any + Send>>,
1445}