use std::path::PathBuf;
pub fn is_pascal_case(name: &str) -> bool {
name.chars().next().map_or(false, |c| c.is_uppercase())
}
pub fn replace_absolute_path_with_project_name(
project_root: PathBuf,
path: PathBuf,
prepend_with: &str,
) -> PathBuf {
let relative_path = path.strip_prefix(project_root).unwrap().to_path_buf();
PathBuf::from(prepend_with).join(relative_path)
}
#[cfg(test)]
pub mod test_utils {
use std::fs;
use tempfile::TempDir;
pub fn create_mock_project(files: &Vec<(&str, &str)>) -> TempDir {
let temp_dir = TempDir::new().unwrap();
let root = temp_dir.path();
for (path, content) in files {
let file_path = root.join(path);
if let Some(parent) = file_path.parent() {
if parent != root {
fs::create_dir_all(parent).unwrap();
}
}
fs::write(file_path, content).unwrap();
}
temp_dir
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_pascal_case() {
assert_eq!(is_pascal_case("PascalCase"), true);
assert_eq!(is_pascal_case("camelCase"), false);
assert_eq!(is_pascal_case("kebab-case"), false);
assert_eq!(is_pascal_case("snake_case"), false);
assert_eq!(is_pascal_case("SCREAMING_SNAKE_CASE"), true);
}
#[test]
fn test_replace_path_with_relative_path() {
assert_eq!(
replace_absolute_path_with_project_name(
PathBuf::from("/Users/asht/Projects/spinne"),
PathBuf::from("/Users/asht/Projects/spinne/src/main.tsx"),
"test-project"
),
PathBuf::from("test-project/src/main.tsx")
);
}
}