Skip to content

Commit

Permalink
prf: helper for recent asrs
Browse files Browse the repository at this point in the history
  • Loading branch information
globin committed Mar 9, 2024
1 parent bba17f4 commit 58b7ed7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/prf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ 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 parse(path: &Path, contents: &[u8]) -> PrfResult {
let file_contents = read_to_string(contents)?;
let settings = PrfParser::parse(Rule::prf, &file_contents).map(|mut pairs| {
Expand Down Expand Up @@ -107,7 +113,7 @@ mod test {
use super::Prf;

#[test]
fn test() {
fn test_basic_paths() {
let prf_path = PathBuf::from("./fixtures/iCAS2.prf");
let prf_contents = fs::read(&prf_path).unwrap();
let prf = Prf::parse(&prf_path, &prf_contents).unwrap();
Expand Down Expand Up @@ -136,4 +142,19 @@ mod test {
.join("./fixtures/EDMM-AeroNav.sct")
);
}

#[test]
fn test_recent_path() {
let prf_path = PathBuf::from("./fixtures/iCAS2.prf");
let prf_contents = fs::read(&prf_path).unwrap();
let prf = Prf::parse(&prf_path, &prf_contents).unwrap();

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

0 comments on commit 58b7ed7

Please sign in to comment.