Skip to content

Commit

Permalink
remove debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
woojiq committed Dec 22, 2023
1 parent ed4bec3 commit 858b7e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
4 changes: 0 additions & 4 deletions helix-core/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ pub fn expand_tilde(path: &Path) -> PathBuf {
// Strategy: start from the first component and move up. Cannonicalize previous path,
// join component, cannonicalize new path, strip prefix and join to the final result
pub fn get_normalized_path(path: &Path) -> PathBuf {
log::debug!("path before normalization: {}", path.to_string_lossy());

let mut components = path.components().peekable();
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
components.next();
Expand Down Expand Up @@ -89,8 +87,6 @@ pub fn get_normalized_path(path: &Path) -> PathBuf {
}
}
}

log::debug!("normalized path: {}", ret.to_string_lossy());
ret
}

Expand Down
40 changes: 35 additions & 5 deletions helix-core/tests/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,42 @@ use std::{
path::{Component, Path, PathBuf},
};

#[cfg(unix)]
use std::os::unix;
#[cfg(windows)]
use std::os::windows;

use helix_core::path::get_normalized_path;
use tempfile::Builder;

// Paths on Windows are almost always case-insensitive.
// Normalization should return the original path.
// E.g. mkdir `CaSe`, normalize(`case`) = `CaSe`.
#[cfg(windows)]
#[test]
fn test_case_folding_windows() -> Result<(), Box<dyn Error>> {
// tmp/root/case
let tmp_prefix = std::env::temp_dir();
set_current_dir(&tmp_prefix)?;

let root = Builder::new().prefix("root-").tempdir()?;
let case = Builder::new().prefix("CaSe-").tempdir_in(&root)?;

let root_without_prefix = root.path().strip_prefix(&tmp_prefix)?;

let lowercase_case = format!(
"case-{}",
case.path()
.file_name()
.unwrap()
.to_string_lossy()
.split_at(5)
.1
);
let test_path = root_without_prefix.join(lowercase_case);
assert_eq!(
get_normalized_path(&test_path),
case.path().strip_prefix(&tmp_prefix)?
);

Ok(())
}

#[test]
fn test_normalize_path() -> Result<(), Box<dyn Error>> {
// tmp/root/
Expand Down Expand Up @@ -44,11 +72,13 @@ fn test_normalize_path() -> Result<(), Box<dyn Error>> {

#[cfg(unix)]
{
use std::os::unix;
unix::fs::symlink(&dir1, &dir_link)?;
unix::fs::symlink(&orig_file, &link)?;
}
#[cfg(windows)]
{
use std::os::windows;
windows::fs::symlink_dir(&dir1, &dir_link)?;
windows::fs::symlink_file(&orig_file, &link)?;
}
Expand Down

0 comments on commit 858b7e7

Please sign in to comment.