1use rush_ecs_core::blueprint::BlueprintString;
2use std::{
3 fs::{read_dir, read_to_string},
4 path::Path,
5};
6
7pub fn file_to_string(path: &Path) -> BlueprintString {
14 read_to_string(path).expect("invalid path")
16}
17
18pub fn dir_to_string(path: &Path) -> BlueprintString {
33 let list_of_files = read_dir(path).expect("invalid path");
34
35 let mut loaded_string = String::default();
37
38 for de in list_of_files {
40 let dir_entry = de.expect("invalid directory entry");
42 let filepath = dir_entry.path();
43 let content = read_to_string(filepath).expect("invalid path");
44
45 loaded_string += format!("{content}\n").as_str();
47 }
48
49 loaded_string
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_file_to_string() {
58 let path = Path::new("mock/fixtures/utils/file_to_string");
59 let string = file_to_string(path);
60 assert_eq!(string, "abcd\n");
61 }
62
63 #[test]
64 fn test_dir_to_string() {
65 let path = Path::new("mock/fixtures/utils/dir_to_string");
66 let string = dir_to_string(path);
67 assert_eq!(string, "a\n\nb\n\n");
68 }
69}