Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod issue; | ||
mod issue_block_link; | ||
|
||
pub use self::issue::*; | ||
pub use self::issue_block_link::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(()) | ||
} | ||
} |