MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / test_format_path

Function test_format_path

crates/chat-cli/src/cli/chat/tools/mod.rs:574–617  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 2

assert_pathsFunction · 0.85
as_strMethod · 0.45

Tested by

no test coverage detected