use super::AstStrategy;
use std::sync::Arc;
pub struct StrategySelector;
impl StrategySelector {
#[must_use]
pub fn select_for_extension(extension: &str) -> Option<Arc<dyn AstStrategy>> {
match extension {
"rs" => Some(Arc::new(super::languages::rust::RustStrategy::new())),
#[cfg(feature = "typescript-ast")]
"ts" | "tsx" => Some(Arc::new(
super::languages::typescript::TypeScriptStrategy::new(),
)),
#[cfg(feature = "typescript-ast")]
"js" | "jsx" | "mjs" => Some(Arc::new(
super::languages::javascript::JavaScriptStrategy::new(),
)),
#[cfg(feature = "python-ast")]
"py" | "pyi" | "pyw" => Some(Arc::new(super::languages::python::PythonStrategy::new())),
#[cfg(feature = "c-ast")]
"c" | "h" => Some(Arc::new(super::languages::c::CStrategy::new())),
#[cfg(feature = "cpp-ast")]
"cpp" | "cxx" | "cc" | "hpp" | "hxx" | "hh" => {
Some(Arc::new(super::languages::cpp::CppStrategy::new()))
}
_ => None,
}
}
#[must_use]
pub fn supported_extensions() -> Vec<&'static str> {
let mut extensions = vec!["rs"];
#[cfg(feature = "typescript-ast")]
{
extensions.extend_from_slice(&["ts", "tsx", "js", "jsx", "mjs"]);
}
#[cfg(feature = "python-ast")]
{
extensions.extend_from_slice(&["py", "pyi", "pyw"]);
}
#[cfg(feature = "c-ast")]
{
extensions.extend_from_slice(&["c", "h"]);
}
#[cfg(feature = "cpp-ast")]
{
extensions.extend_from_slice(&["cpp", "cxx", "cc", "hpp", "hxx", "hh"]);
}
extensions
}
}
#[cfg(test)]
mod property_tests {
use proptest::prelude::*;
proptest! {
#[test]
fn basic_property_stability(_input in ".*") {
prop_assert!(true);
}
#[test]
fn module_consistency_check(_x in 0u32..1000) {
prop_assert!(_x < 1001);
}
}
}