Skip to content

Commit

Permalink
Merge pull request #34 from tamada/bugs/panicked_in_specifying_dir
Browse files Browse the repository at this point in the history
Bugs/panicked in specifying dir
  • Loading branch information
tamada authored Dec 26, 2024
2 parents 9819907 + 58fb9a1 commit 56d9d05
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Rust Debug Launch",
"program": "${workspaceRoot}/target/debug/${workspaceRootFolderName}",
"args": ["docs"],
"cwd": "${workspaceRoot}",
"sourceLanguages": ["rust"]
}
]
}
7 changes: 4 additions & 3 deletions src/dirs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf};
use std::{fs, path::{Path, PathBuf}};

use crate::cli::{Result, SiblingError};

Expand All @@ -20,7 +20,8 @@ impl Dirs {
}
} else if current_dir.exists() {
if current_dir.is_dir() {
build_dirs(current_dir.clone().parent(), current_dir)
let current = fs::canonicalize(&current_dir).unwrap();
build_dirs(current.clone().parent(), current)
} else {
Err(SiblingError::NotDir(current_dir))
}
Expand Down Expand Up @@ -48,7 +49,7 @@ fn build_dirs(parent: Option<&Path>, current: PathBuf) -> Result<Dirs> {
None => return Err(SiblingError::NoParent(current)),
};
let mut errs = vec![];
let dirs = collect_dirs(parent, &mut errs);
let dirs = collect_dirs(&parent, &mut errs);
if !errs.is_empty() {
Err(SiblingError::Array(errs))
} else {
Expand Down
18 changes: 9 additions & 9 deletions src/nexter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod tests {
let mut dirs = Dirs::new("testdata/c".into()).unwrap();
let nexter = build_nexter(NexterType::First);
match nexter.next(&mut dirs, 1) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/a")),
Some(p) => assert!(p.ends_with("testdata/a")),
None => panic!("unexpected None"),
}
}
Expand All @@ -108,7 +108,7 @@ mod tests {
let mut dirs = Dirs::new("testdata/k".into()).unwrap();
let nexter = build_nexter(NexterType::Last);
match nexter.next(&mut dirs, 1) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/z")),
Some(p) => assert!(p.ends_with("testdata/z")),
None => panic!("unexpected None"),
}
}
Expand All @@ -118,15 +118,15 @@ mod tests {
let mut dirs = Dirs::new("testdata/c".into()).unwrap();
let nexter = build_nexter(NexterType::Next);
match nexter.next(&mut dirs, 1) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/d")),
Some(p) => assert!(p.ends_with("testdata/d")),
None => panic!("unexpected None"),
}
match nexter.next(&mut dirs, 2) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/e")),
Some(p) => assert!(p.ends_with("testdata/e")),
None => panic!("unexpected None"),
}
match nexter.next(&mut dirs, 26) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/z")),
Some(p) => assert!(p.ends_with("testdata/z")),
None => panic!("unexpected None"),
}
match nexter.next(&mut dirs, 1) {
Expand All @@ -140,19 +140,19 @@ mod tests {
let mut dirs = Dirs::new("testdata/k".into()).unwrap();
let nexter = build_nexter(NexterType::Previous);
match nexter.next(&mut dirs, 1) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/j")),
Some(p) => assert!(p.ends_with("testdata/j")),
None => panic!("unexpected None"),
}
match nexter.next(&mut dirs, 1) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/j")),
Some(p) => assert!(p.ends_with("testdata/j")),
None => panic!("unexpected None"),
}
match nexter.next(&mut dirs, 4) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/g")),
Some(p) => assert!(p.ends_with("testdata/g")),
None => panic!("unexpected None"),
}
match nexter.next(&mut dirs, 26) {
Some(p) => assert_eq!(p, PathBuf::from("testdata/a")),
Some(p) => assert!(p.ends_with("testdata/a")),
None => panic!("unexpected None"),
}
match nexter.next(&mut dirs, 1) {
Expand Down

0 comments on commit 56d9d05

Please sign in to comment.