use rush_ecs_core::blueprint::BlueprintString;
use std::{
fs::{read_dir, read_to_string},
path::Path,
};
pub fn file_to_string(path: &Path) -> BlueprintString {
read_to_string(path).expect("invalid path")
}
pub fn dir_to_string(path: &Path) -> BlueprintString {
let list_of_files = read_dir(path).expect("invalid path");
let mut loaded_string = String::default();
for de in list_of_files {
let dir_entry = de.expect("invalid directory entry");
let filepath = dir_entry.path();
let content = read_to_string(filepath).expect("invalid path");
loaded_string += format!("{content}\n").as_str();
}
loaded_string
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_file_to_string() {
let path = Path::new("mock/fixtures/utils/file_to_string");
let string = file_to_string(path);
assert_eq!(string, "abcd\n");
}
#[test]
fn test_dir_to_string() {
let path = Path::new("mock/fixtures/utils/dir_to_string");
let string = dir_to_string(path);
assert_eq!(string, "a\n\nb\n\n");
}
}