1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std::time::Duration;
use crate::selector::Selector;
/// XCTest-like expectation descriptor.
#[derive(Debug, Clone)]
pub struct Expectation {
pub(crate) kind: ExpectationKind,
pub(crate) inverted: bool,
}
impl Expectation {
/// Marks this expectation as inverted.
#[must_use]
pub const fn inverted(mut self) -> Self {
self.inverted = true;
self
}
}
#[derive(Debug, Clone)]
pub enum ExpectationKind {
/// Wait for selector existence.
Exists(Selector),
/// Wait for selector absence.
NotExists(Selector),
/// Wait for selector value equality.
ValueEquals { selector: Selector, value: String },
}
/// Wait behavior configuration.
#[derive(Debug, Clone, Copy)]
pub struct WaitOptions {
/// Maximum time to wait before returning a timeout result.
pub timeout: Duration,
/// Whether non-inverted expectations must be fulfilled in list order.
pub enforce_order: bool,
}
impl WaitOptions {
/// Creates wait options with the provided timeout.
#[must_use]
pub const fn new(timeout: Duration) -> Self {
Self {
timeout,
enforce_order: false,
}
}
/// Sets whether expectations must be fulfilled in order.
#[must_use]
pub const fn enforce_order(mut self, enforce_order: bool) -> Self {
self.enforce_order = enforce_order;
self
}
}
impl Default for WaitOptions {
fn default() -> Self {
Self::new(Duration::from_secs(2))
}
}
/// XCTest-like wait result.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WaitResult {
/// All expectations were fulfilled.
Completed,
/// The wait timed out.
TimedOut,
/// A later expectation was fulfilled before an earlier ordered expectation.
IncorrectOrder,
/// An inverted expectation became true.
InvertedFulfillment,
/// The wait was interrupted.
Interrupted,
}