ferridriver_expect/
lib.rs1#![allow(
2 clippy::missing_errors_doc,
3 clippy::missing_panics_doc,
4 clippy::must_use_candidate,
5 clippy::module_name_repetitions,
6 clippy::cast_possible_truncation,
7 clippy::cast_precision_loss,
8 clippy::cast_sign_loss,
9 clippy::cast_possible_wrap,
10 clippy::uninlined_format_args,
11 clippy::needless_pass_by_value,
12 clippy::doc_markdown,
13 clippy::match_same_arms,
14 clippy::should_implement_trait,
15 clippy::manual_let_else,
16 clippy::too_many_lines,
17 clippy::return_self_not_must_use,
18 clippy::wrong_self_convention,
22 clippy::redundant_closure_for_method_calls
23)]
24
25pub mod api_response;
39pub mod asymmetric;
40pub mod builder;
41pub mod diff;
42pub mod locator;
43pub mod page;
44pub mod poll;
45pub mod throw;
46pub mod value;
47
48pub use asymmetric::{ASYM_TAG_KEY, Asymmetric, TypeTag, deep_equal, match_object};
49pub use builder::{
50 Expect, ExpectPoll, HaveCssOptions, InViewportOptions, ToPassOptions, expect, expect_configured, expect_poll,
51 to_pass, to_pass_with_options,
52};
53pub use diff::{json_diff, pretty_json, unified_diff};
54pub use poll::{DEFAULT_EXPECT_TIMEOUT, ExpectContext, MatchError, POLL_INTERVALS, poll_until};
55pub use throw::{ExpectFn, ThrowMatcher, ThrownError, expect_fn};
56pub use value::{ExpectValue, StringOrRegex, expect_value};
57
58#[derive(Debug, Clone)]
67pub struct AssertionFailure {
68 pub message: String,
69 pub diff: Option<String>,
70 pub location: Option<CallerLocation>,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq)]
77pub struct CallerLocation {
78 pub file: &'static str,
79 pub line: u32,
80 pub column: u32,
81}
82
83impl CallerLocation {
84 #[must_use]
85 pub fn from_std(loc: &'static std::panic::Location<'static>) -> Self {
86 Self {
87 file: loc.file(),
88 line: loc.line(),
89 column: loc.column(),
90 }
91 }
92}
93
94impl std::fmt::Display for CallerLocation {
95 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96 write!(f, "{}:{}:{}", self.file, self.line, self.column)
97 }
98}
99
100impl AssertionFailure {
101 pub fn new(message: impl Into<String>, diff: Option<String>) -> Self {
102 Self {
103 message: message.into(),
104 diff,
105 location: None,
106 }
107 }
108
109 #[must_use]
110 pub fn with_location(mut self, loc: CallerLocation) -> Self {
111 self.location = Some(loc);
112 self
113 }
114}
115
116impl std::fmt::Display for AssertionFailure {
117 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
118 f.write_str(&self.message)
119 }
120}
121
122impl std::error::Error for AssertionFailure {}