use anyhow::Result;
use std::path::PathBuf;
#[allow(clippy::too_many_arguments)]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn handle_analyze_name_similarity(
project_path: PathBuf,
query: String,
top_k: usize,
phonetic: bool,
scope: crate::cli::SearchScope,
threshold: f64,
format: crate::cli::NameSimilarityOutputFormat,
include: Option<String>,
exclude: Option<String>,
output: Option<PathBuf>,
perf: bool,
fuzzy: bool,
case_sensitive: bool,
) -> Result<()> {
crate::cli::handle_analyze_name_similarity(
project_path,
query,
top_k,
phonetic,
scope,
threshold as f32,
format,
include,
exclude,
output,
perf,
fuzzy,
case_sensitive,
)
.await
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use super::*;
use tempfile::TempDir;
#[tokio::test]
async fn test_handle_analyze_name_similarity_basic() {
let temp_dir = TempDir::new().unwrap();
let result = handle_analyze_name_similarity(
temp_dir.path().to_path_buf(),
"test_function".to_string(),
10,
false,
crate::cli::SearchScope::All,
0.7,
crate::cli::NameSimilarityOutputFormat::Json,
None,
None,
None,
false,
false,
false,
)
.await;
assert!(result.is_err() || result.is_ok());
}
#[tokio::test]
async fn test_handle_analyze_name_similarity_with_options() {
let temp_dir = TempDir::new().unwrap();
let output_path = temp_dir.path().join("similarity.json");
let result = handle_analyze_name_similarity(
temp_dir.path().to_path_buf(),
"handle_request".to_string(),
5,
true, crate::cli::SearchScope::Functions,
0.8,
crate::cli::NameSimilarityOutputFormat::Detailed,
Some("*.rs".to_string()),
Some("test_*.rs".to_string()),
Some(output_path),
true, true, true, )
.await;
assert!(result.is_err() || result.is_ok());
}
#[test]
fn test_name_similarity_parameters() {
let query = "test_query".to_string();
let top_k = 15;
let threshold = 0.6;
assert!(!query.is_empty());
assert!(top_k > 0);
assert!((0.0..=1.0).contains(&threshold));
}
#[test]
fn test_search_scope_variations() {
use crate::cli::SearchScope;
let scopes = vec![
SearchScope::All,
SearchScope::Functions,
SearchScope::Types,
SearchScope::Variables,
];
for scope in scopes {
match scope {
SearchScope::All => {}
SearchScope::Functions => {}
SearchScope::Types => {}
SearchScope::Variables => {}
}
}
}
#[test]
fn test_output_format_variations() {
use crate::cli::NameSimilarityOutputFormat;
let formats = vec![
NameSimilarityOutputFormat::Json,
NameSimilarityOutputFormat::Detailed,
NameSimilarityOutputFormat::Csv,
NameSimilarityOutputFormat::Summary,
NameSimilarityOutputFormat::Markdown,
];
for format in formats {
match format {
NameSimilarityOutputFormat::Json => {}
NameSimilarityOutputFormat::Detailed => {}
NameSimilarityOutputFormat::Csv => {}
NameSimilarityOutputFormat::Summary => {}
NameSimilarityOutputFormat::Markdown => {}
NameSimilarityOutputFormat::Human => {}
}
}
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[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);
}
}
}