story-kit: merge 104_story_test_coverage_io_search_rs_to_95
This commit is contained in:
@@ -161,4 +161,58 @@ mod tests {
|
||||
assert_eq!(results.len(), 1);
|
||||
assert_eq!(results[0].path, "kept.txt");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn search_files_with_session_state() {
|
||||
let dir = setup_project(&[("found.txt", "target_text")]);
|
||||
let state = SessionState::default();
|
||||
*state.project_root.lock().unwrap() = Some(dir.path().to_path_buf());
|
||||
|
||||
let results = search_files("target_text".to_string(), &state).await.unwrap();
|
||||
|
||||
assert_eq!(results.len(), 1);
|
||||
assert_eq!(results[0].path, "found.txt");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn search_files_errors_without_project_root() {
|
||||
let state = SessionState::default();
|
||||
|
||||
let result = search_files("query".to_string(), &state).await;
|
||||
|
||||
assert!(result.is_err());
|
||||
assert!(result.unwrap_err().contains("No project"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn search_result_serializes_and_debugs() {
|
||||
let sr = SearchResult {
|
||||
path: "src/main.rs".to_string(),
|
||||
matches: 3,
|
||||
};
|
||||
let json = serde_json::to_string(&sr).unwrap();
|
||||
assert!(json.contains("src/main.rs"));
|
||||
assert!(json.contains("3"));
|
||||
|
||||
let debug = format!("{sr:?}");
|
||||
assert!(debug.contains("SearchResult"));
|
||||
assert!(debug.contains("src/main.rs"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn skips_binary_files() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
// Write a file with invalid UTF-8 bytes
|
||||
let binary_path = dir.path().join("binary.bin");
|
||||
fs::write(&binary_path, [0xFF, 0xFE, 0x00, 0x01]).unwrap();
|
||||
// Write a valid text file with the search term
|
||||
fs::write(dir.path().join("text.txt"), "findme").unwrap();
|
||||
|
||||
let results = search_files_impl("findme".to_string(), dir.path().to_path_buf())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(results.len(), 1);
|
||||
assert_eq!(results[0].path, "text.txt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user