use std::io;
use std::path::{Path, PathBuf};
pub fn load_history_file(path: impl AsRef<Path>) -> io::Result<String> {
std::fs::read_to_string(path)
}
pub fn default_history_path() -> Option<PathBuf> {
crate::shell::Shell::Bash.default_history_path()
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
#[test]
fn loads_existing_file() {
let dir = std::env::temp_dir().join("shellist_test_load");
fs::write(&dir, "ls\ngit status\n").unwrap();
let content = load_history_file(dir.to_str().unwrap()).unwrap();
assert_eq!(content, "ls\ngit status\n");
fs::remove_file(&dir).unwrap();
}
#[test]
fn returns_error_for_missing_file() {
let result = load_history_file("/tmp/nonexistent_shellist_file_12345");
assert!(result.is_err());
}
#[test]
fn default_path_ends_with_bash_history() {
let path = default_history_path().unwrap();
assert_eq!(path.file_name().unwrap(), ".bash_history");
}
#[test]
fn default_path_is_absolute() {
let path = default_history_path().unwrap();
assert!(path.is_absolute());
}
}