()
| 572 | |
| 573 | #[tokio::test] |
| 574 | async fn test_format_path() { |
| 575 | async fn assert_paths(cwd: &str, path: &str, expected: &str) { |
| 576 | let os = Os::new().await.unwrap(); |
| 577 | let cwd = sanitize_path_tool_arg(&os, cwd); |
| 578 | let path = sanitize_path_tool_arg(&os, path); |
| 579 | let fs = os.fs; |
| 580 | fs.create_dir_all(&cwd).await.unwrap(); |
| 581 | fs.create_dir_all(&path).await.unwrap(); |
| 582 | |
| 583 | let formatted = format_path(&cwd, &path); |
| 584 | |
| 585 | if Path::new(expected).is_absolute() { |
| 586 | // If the expected path is relative, we need to ensure it is relative to the cwd. |
| 587 | let expected = fs.chroot_path_str(expected); |
| 588 | |
| 589 | assert!(formatted == expected, "Expected '{}' to be '{}'", formatted, expected); |
| 590 | |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | assert!( |
| 595 | formatted.contains(expected), |
| 596 | "Expected '{}' to be '{}'", |
| 597 | formatted, |
| 598 | expected |
| 599 | ); |
| 600 | } |
| 601 | |
| 602 | // Test relative path from src to Downloads (sibling directories) |
| 603 | assert_paths( |
| 604 | format!("{ACTIVE_USER_HOME}{MAIN_SEPARATOR}src").as_str(), |
| 605 | format!("{ACTIVE_USER_HOME}{MAIN_SEPARATOR}Downloads").as_str(), |
| 606 | format!("..{MAIN_SEPARATOR}Downloads").as_str(), |
| 607 | ) |
| 608 | .await; |
| 609 | |
| 610 | // Test absolute path that should stay absolute (going up too many levels) |
| 611 | assert_paths( |
| 612 | format!("{ACTIVE_USER_HOME}{MAIN_SEPARATOR}projects{MAIN_SEPARATOR}some{MAIN_SEPARATOR}project").as_str(), |
| 613 | format!("{ACTIVE_USER_HOME}{MAIN_SEPARATOR}other").as_str(), |
| 614 | format!("{ACTIVE_USER_HOME}{MAIN_SEPARATOR}other").as_str(), |
| 615 | ) |
| 616 | .await; |
| 617 | } |
| 618 | } |
nothing calls this directly
no test coverage detected