-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue_block_link.rs
60 lines (47 loc) · 1.34 KB
/
issue_block_link.rs
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
use crate::{IssueBlockLinkId, IssueBlockLinkStatus, IssueId};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IssueBlockLink {
id: IssueBlockLinkId,
status: IssueBlockLinkStatus,
}
impl IssueBlockLink {
pub(crate) fn new(id: IssueBlockLinkId) -> Self {
Self {
id,
status: IssueBlockLinkStatus::Blocked,
}
}
pub fn issue_id(&self) -> &IssueId {
self.id.issue_id()
}
pub fn blocked_issue_id(&self) -> &IssueId {
self.id.blocked_issue_id()
}
pub fn is_blocked(&self) -> bool {
self.status == IssueBlockLinkStatus::Blocked
}
pub(crate) fn block(&mut self) {
self.status = IssueBlockLinkStatus::Blocked;
}
pub(crate) fn unblock(&mut self) {
self.status = IssueBlockLinkStatus::Unblocked;
}
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use super::*;
#[test]
fn test() -> anyhow::Result<()> {
let id = IssueBlockLinkId::from_str("1 -> 2")?;
let mut link = IssueBlockLink::new(id.clone());
assert_eq!(link.issue_id(), id.issue_id());
assert_eq!(link.blocked_issue_id(), id.blocked_issue_id());
assert!(link.is_blocked());
link.unblock();
assert!(!link.is_blocked());
link.block();
assert!(link.is_blocked());
Ok(())
}
}