diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c8b38f4 --- /dev/null +++ b/.vscode/launch.json @@ -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"] + } + ] +} \ No newline at end of file diff --git a/src/dirs.rs b/src/dirs.rs index 4d8f773..e0b0022 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -1,4 +1,4 @@ -use std::path::{Path, PathBuf}; +use std::{fs, path::{Path, PathBuf}}; use crate::cli::{Result, SiblingError}; @@ -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(¤t_dir).unwrap(); + build_dirs(current.clone().parent(), current) } else { Err(SiblingError::NotDir(current_dir)) } @@ -48,7 +49,7 @@ fn build_dirs(parent: Option<&Path>, current: PathBuf) -> Result { 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 { diff --git a/src/nexter.rs b/src/nexter.rs index ebd0868..46e6668 100644 --- a/src/nexter.rs +++ b/src/nexter.rs @@ -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"), } } @@ -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"), } } @@ -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) { @@ -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) {