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
/// Used to uniquely identify a test in a flow
#[derive(Clone, Serialize, PartialEq, Hash, Eq)]
pub struct FlowID {
id: String,
_private: (),
}
impl FlowID {
/// Generate a new ID from a string. No checking is done at the point of creation
/// to guarantee uniqueness, but it will be checked later in the generation process.
/// String-based IDs are forced to lowercase to enable case-insensitive comparisions.
pub fn from_str(id: &str) -> FlowID {
FlowID {
id: id.to_lowercase(),
_private: (),
}
}
/// Generate a new ID from an integer. No checking is done at the point of creation
/// to guarantee uniqueness, but it will be checked later in the generation process.
pub fn from_int(id: usize) -> FlowID {
FlowID {
id: format!("t{}", id),
_private: (),
}
}
/// Generate a new unique ID, this will have the format "_t{unique_id}_" which should
/// avoid collisions with user-defined IDs
pub fn new() -> FlowID {
FlowID::from_str(&format!("_t{}_", crate::PROG_GEN_CONFIG.generate_unique_id()))
}
/// Returns true if the ID refers to a test external to this flow, currently defined by the ID
/// starting with "extern_"
pub fn is_external(&self) -> bool {
self.id.starts_with("extern")
}
pub fn to_string(&self) -> String {
self.id.clone()
}
pub fn to_str(&self) -> &str {
&self.id
}
}
impl std::fmt::Display for FlowID {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "FlowID(\"{}\")", self.id)
}
}
impl std::fmt::Debug for FlowID {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "FlowID(\"{}\")", self.id)
}
}