mirror of https://github.com/helix-editor/helix
85 lines
4.8 KiB
Rust
85 lines
4.8 KiB
Rust
#[cfg(all(feature = "integration", unix))] // Keep cfg for consistency, though it won't be an integration test
|
|
mod test {
|
|
use std::{fs, path::PathBuf, os::unix::fs::symlink};
|
|
use tempfile::tempdir;
|
|
use indoc::indoc;
|
|
use helix_lsp::lsp::Url; // Only Url needed for this simplified test
|
|
|
|
// Note: This is no longer an async tokio test.
|
|
// Note: This does not use AppBuilder or Application.
|
|
#[test]
|
|
fn verify_symlink_canonicalization_for_uri() -> anyhow::Result<()> {
|
|
println!("--- Test verify_symlink_canonicalization_for_uri started ---");
|
|
|
|
// 1. Create a temporary directory for test files.
|
|
let temp_dir = tempdir()?;
|
|
let dir_path = temp_dir.path();
|
|
println!("Temporary directory created: {:?}", dir_path);
|
|
|
|
// 2. Inside this directory:
|
|
// a. Create original_file.py
|
|
let original_file_path = dir_path.join("original_file.py");
|
|
let python_content = indoc! {r#"
|
|
def my_function():
|
|
pass
|
|
|
|
my_function()
|
|
"#};
|
|
fs::write(&original_file_path, python_content)?;
|
|
println!("original_file.py created at: {:?}", original_file_path);
|
|
|
|
// b. Create a symlink linked_file.py pointing to original_file.py
|
|
let linked_file_path = dir_path.join("linked_file.py");
|
|
symlink(&original_file_path, &linked_file_path)?;
|
|
println!("linked_file.py created at: {:?}, pointing to {:?}", linked_file_path, original_file_path);
|
|
|
|
// Core Logic Verification:
|
|
// Get the canonical path for both the original and the symlinked file.
|
|
let canonical_original_path = original_file_path.canonicalize()?;
|
|
let canonical_linked_path = linked_file_path.canonicalize()?;
|
|
println!("Canonical original path: {:?}", canonical_original_path);
|
|
println!("Canonical linked path: {:?}", canonical_linked_path);
|
|
|
|
// Assert that the canonical paths are the same.
|
|
assert_eq!(canonical_original_path, canonical_linked_path, "Canonical paths of original and symlink should be identical.");
|
|
println!("Assertion 1 passed: Canonical paths are identical.");
|
|
|
|
// Convert these canonical paths to file URIs.
|
|
let uri_from_original = Url::from_file_path(canonical_original_path).map_err(|_| anyhow::anyhow!("Failed to create URI from original path"))?;
|
|
let uri_from_linked = Url::from_file_path(canonical_linked_path).map_err(|_| anyhow::anyhow!("Failed to create URI from linked path"))?;
|
|
println!("URI from original's canonical path: {:?}", uri_from_original);
|
|
println!("URI from linked file's canonical path: {:?}", uri_from_linked);
|
|
|
|
// Assert that the URIs are the same.
|
|
assert_eq!(uri_from_original, uri_from_linked, "URIs from canonical paths should be identical.");
|
|
println!("Assertion 2 passed: URIs from canonical paths are identical.");
|
|
|
|
// Also, check if creating a URI from the non-canonical symlink path,
|
|
// and then canonicalizing the path from *that* URI (if possible, though Url doesn't directly do that),
|
|
// would match. The key is that `helix_stdx::path::canonicalize` should be used *before* Uri creation
|
|
// as per the original subtask that modified `convert_url_to_uri`.
|
|
|
|
// The original change was: Uri::File(helix_stdx::path::canonicalize(path).into())
|
|
// So, if we simulate this:
|
|
// 1. Path comes from url.to_file_path() - this would be /path/to/linked_file.py
|
|
// 2. Then helix_stdx::path::canonicalize is applied to it.
|
|
|
|
let path_from_symlink_url = linked_file_path; // Simulating url.to_file_path() for the symlink
|
|
let canonicalized_path_for_uri_construction = helix_stdx::path::canonicalize(path_from_symlink_url).map_err(|e| anyhow::anyhow!("helix_stdx::path::canonicalize failed: {}",e))?;
|
|
println!("Path from symlink after helix_stdx::path::canonicalize: {:?}", canonicalized_path_for_uri_construction);
|
|
|
|
assert_eq!(canonicalized_path_for_uri_construction, canonical_original_path, "helix_stdx::path::canonicalize(symlink_path) should yield original's canonical path.");
|
|
println!("Assertion 3 passed: helix_stdx::path::canonicalize(symlink_path) is correct.");
|
|
|
|
let constructed_uri = Url::from_file_path(canonicalized_path_for_uri_construction).map_err(|_| anyhow::anyhow!("Failed to create URI from stdx canonicalized path"))?;
|
|
assert_eq!(constructed_uri, uri_from_original, "URI constructed using helix_stdx::path::canonicalize should match original's canonical URI.");
|
|
println!("Assertion 4 passed: Final URI construction matches.");
|
|
|
|
|
|
// Clean up the temporary directory
|
|
temp_dir.close()?;
|
|
println!("--- Test verify_symlink_canonicalization_for_uri finished ---");
|
|
Ok(())
|
|
}
|
|
}
|