Skip to main content

sz_orm_core/
binding_coverage.rs

1//! 绑定层 API 覆盖率报告(v7.5.0 组6.4)
2//!
3//! 描述各语言绑定(CABI / Python / Java / Go / C++)对 sz-orm-core 公开 API 的覆盖情况。
4
5use serde::{Deserialize, Serialize};
6
7/// 绑定语言
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9pub enum BindingLanguage {
10    /// C ABI
11    Cabi,
12    /// Python(pyo3)
13    Python,
14    /// Java(JNI)
15    Java,
16    /// Go(cgo)
17    Go,
18    /// C++(cxx)
19    Cpp,
20}
21
22/// 绑定层 API 覆盖率报告
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct BindingCoverageReport {
25    /// 绑定语言
26    pub language: BindingLanguage,
27    /// 核心 API 总数
28    pub core_api_count: usize,
29    /// 已绑定 API 数
30    pub bound_api_count: usize,
31    /// 覆盖率(bound_api_count / core_api_count)
32    pub coverage_rate: f64,
33    /// 缺失 API 列表
34    pub missing_apis: Vec<String>,
35    /// 端到端测试已覆盖数
36    pub end_to_end_tested: usize,
37}
38
39impl BindingCoverageReport {
40    /// 创建新的覆盖率报告
41    pub fn new(
42        language: BindingLanguage,
43        core_api_count: usize,
44        bound_api_count: usize,
45        missing_apis: Vec<String>,
46        end_to_end_tested: usize,
47    ) -> Self {
48        let coverage_rate = if core_api_count == 0 {
49            0.0
50        } else {
51            bound_api_count as f64 / core_api_count as f64
52        };
53        Self {
54            language,
55            core_api_count,
56            bound_api_count,
57            coverage_rate,
58            missing_apis,
59            end_to_end_tested,
60        }
61    }
62
63    /// 验证端到端测试覆盖所有已绑定 API
64    pub fn is_fully_tested(&self) -> bool {
65        self.end_to_end_tested == self.bound_api_count
66    }
67
68    /// 序列化为 JSON
69    pub fn to_json(&self) -> Result<String, serde_json::Error> {
70        serde_json::to_string_pretty(self)
71    }
72}