Skip to content

Commit

Permalink
prf: recent asr as Option
Browse files Browse the repository at this point in the history
  • Loading branch information
globin committed Mar 9, 2024
1 parent 58b7ed7 commit 74abe1f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/prf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ impl Prf {
.map(|path| self.path.parent().unwrap().join(path))
}

pub fn recent_path(&self, num: u8) -> PathBuf {
let recent_path =
from_prf_path(&self.settings.0[&("RecentFiles".to_string(), format!("Recent{num}"))]);
self.path.parent().unwrap().join(recent_path)
pub fn recent_path(&self, num: u8) -> Option<PathBuf> {
self.settings
.0
.get(&("RecentFiles".to_string(), format!("Recent{num}")))
.map(|recent_path| self.path.parent().unwrap().join(from_prf_path(recent_path)))
}

pub fn parse(path: &Path, contents: &[u8]) -> PrfResult {
Expand Down Expand Up @@ -151,10 +152,13 @@ mod test {

assert_eq!(
prf.recent_path(1),
PathBuf::from(".")
.canonicalize()
.unwrap()
.join("./fixtures/EDMM/ASR/iCAS2/EDMM_CTR.asr")
Some(
PathBuf::from(".")
.canonicalize()
.unwrap()
.join("./fixtures/EDMM/ASR/iCAS2/EDMM_CTR.asr")
)
);
assert_eq!(prf.recent_path(2), None);
}
}

0 comments on commit 74abe1f

Please sign in to comment.