use recoco::ops::factory_bases::{SimpleFunctionFactoryBase, TargetFactoryBase};
use recoco::ops::sdk::ExecutorFactoryRegistry;
use recoco::prelude::Error as RecocoError;
use crate::functions::{
calls::ExtractCallsFactory, imports::ExtractImportsFactory, parse::ThreadParseFactory,
symbols::ExtractSymbolsFactory,
};
use crate::targets::d1::D1TargetFactory;
pub struct ThreadOperators;
impl ThreadOperators {
pub const OPERATORS: &'static [&'static str] = &[
"thread_parse",
"extract_symbols",
"extract_imports",
"extract_calls",
];
pub const TARGETS: &'static [&'static str] = &["d1"];
pub fn is_thread_operator(name: &str) -> bool {
Self::OPERATORS.contains(&name)
}
pub fn is_thread_target(name: &str) -> bool {
Self::TARGETS.contains(&name)
}
pub fn register_all(registry: &mut ExecutorFactoryRegistry) -> Result<(), RecocoError> {
ThreadParseFactory.register(registry)?;
ExtractSymbolsFactory.register(registry)?;
ExtractImportsFactory.register(registry)?;
ExtractCallsFactory.register(registry)?;
D1TargetFactory.register(registry)?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_operator_names() {
assert!(ThreadOperators::is_thread_operator("thread_parse"));
assert!(ThreadOperators::is_thread_operator("extract_symbols"));
assert!(ThreadOperators::is_thread_operator("extract_imports"));
assert!(ThreadOperators::is_thread_operator("extract_calls"));
assert!(!ThreadOperators::is_thread_operator("unknown_op"));
}
#[test]
fn test_operator_count() {
assert_eq!(ThreadOperators::OPERATORS.len(), 4);
}
#[test]
fn test_target_names() {
assert!(ThreadOperators::is_thread_target("d1"));
assert!(!ThreadOperators::is_thread_target("unknown_target"));
}
#[test]
fn test_target_count() {
assert_eq!(ThreadOperators::TARGETS.len(), 1);
}
#[test]
fn test_register_all() {
let mut registry = ExecutorFactoryRegistry::new();
ThreadOperators::register_all(&mut registry).expect("registration should succeed");
}
}