use std::path::{Path, PathBuf};
pub const WRAPPED_GLSL_FILE_NAME: &str = "par_term_debug_wrapped.glsl";
pub fn debug_dump_dir() -> PathBuf {
std::env::temp_dir()
}
pub fn transpiled_wgsl_path(shader_name: &str) -> PathBuf {
let stem = Path::new(shader_name)
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or(shader_name);
debug_dump_dir().join(format!("par_term_{stem}_shader.wgsl"))
}
pub fn wrapped_glsl_path() -> PathBuf {
debug_dump_dir().join(WRAPPED_GLSL_FILE_NAME)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dumps_land_in_the_system_temp_dir() {
assert!(transpiled_wgsl_path("crt").starts_with(std::env::temp_dir()));
assert!(wrapped_glsl_path().starts_with(std::env::temp_dir()));
}
#[test]
fn shader_name_is_reduced_to_its_stem() {
let expected = debug_dump_dir().join("par_term_crt_shader.wgsl");
assert_eq!(transpiled_wgsl_path("crt"), expected);
assert_eq!(transpiled_wgsl_path("crt.glsl"), expected);
assert_eq!(
transpiled_wgsl_path("/home/u/.config/par-term/shaders/crt.glsl"),
expected
);
}
#[test]
fn both_dump_kinds_share_one_directory() {
assert_eq!(
transpiled_wgsl_path("crt").parent(),
wrapped_glsl_path().parent()
);
}
}