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
use uuid::Uuid;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct CustomIconUuid(pub Uuid);
impl CustomIconUuid {
pub fn new_random() -> CustomIconUuid {
CustomIconUuid(Uuid::new_v4())
}
pub fn nil() -> CustomIconUuid {
CustomIconUuid(Uuid::nil())
}
}
impl Default for CustomIconUuid {
fn default() -> CustomIconUuid {
CustomIconUuid::nil()
}
}
#[cfg(test)]
mod tests {
use super::*;
use uuid::Uuid;
#[test]
fn test_new_random_returns_random_custom_icon_uuids() {
let a = CustomIconUuid::new_random();
let b = CustomIconUuid::new_random();
assert!(a != b);
}
#[test]
fn test_nil_returns_nil_uuid() {
let expected = Uuid::nil();
let actual = CustomIconUuid::nil().0;
assert_eq!(actual, expected);
}
#[test]
fn test_default_returns_nil_custom_icon_uuid() {
let expected = CustomIconUuid::nil();
let actual = CustomIconUuid::default();
assert_eq!(actual, expected);
}
}