优化: 项目文件树/依赖图组件 + 灵感对抗校验 + 小程序脚本 + 模块管理
This commit is contained in:
@@ -484,6 +484,22 @@ impl Priority {
|
||||
Priority::Critical => "critical",
|
||||
}
|
||||
}
|
||||
|
||||
/// 从 i32 解析优先级(对齐**前端约定** 0=Critical/1=High/2=Medium/3=Low,
|
||||
/// 与 src-tauri commands::idea::priority_from_i32 兜底语义一致,统一调用入口)。
|
||||
///
|
||||
/// 注意:enum discriminant 与前端相反(Low=0/Critical=3,历史定义),
|
||||
/// 勿用 `p as Priority` 转换——本函数手动映射前端语义,与 `as_str` 序列化
|
||||
/// ("low"/"critical") 互不干扰。越界/负值(含 4+、-1 等)统一归并 Low。
|
||||
pub fn from_i32(p: i32) -> Priority {
|
||||
match p {
|
||||
0 => Priority::Critical,
|
||||
1 => Priority::High,
|
||||
2 => Priority::Medium,
|
||||
// 3(低)与越界/负值统一归 Low,对齐现有 priority_from_i32 读侧语义
|
||||
_ => Priority::Low,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Priority {
|
||||
@@ -503,7 +519,7 @@ pub fn new_id() -> String {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::TaskStatus;
|
||||
use super::{Priority, TaskStatus};
|
||||
|
||||
// 合法值:覆盖全部枚举变体(与 as_str 一致)
|
||||
#[test]
|
||||
@@ -592,4 +608,33 @@ mod tests {
|
||||
// 数量应等于枚举变体数
|
||||
assert_eq!(TaskStatus::valid_values().len(), 7);
|
||||
}
|
||||
|
||||
// ── Priority::from_i32(对齐前端约定 0=Critical/1=High/2=Medium/3=Low)──
|
||||
|
||||
#[test]
|
||||
fn priority_from_i32_maps_frontend_semantics() {
|
||||
assert_eq!(Priority::from_i32(0), Priority::Critical);
|
||||
assert_eq!(Priority::from_i32(1), Priority::High);
|
||||
assert_eq!(Priority::from_i32(2), Priority::Medium);
|
||||
assert_eq!(Priority::from_i32(3), Priority::Low);
|
||||
}
|
||||
|
||||
// 越界/负值统一归并 Low(对齐 src-tauri priority_from_i32 的 `_` 兜底)
|
||||
#[test]
|
||||
fn priority_from_i32_out_of_range_falls_back_to_low() {
|
||||
assert_eq!(Priority::from_i32(4), Priority::Low);
|
||||
assert_eq!(Priority::from_i32(99), Priority::Low);
|
||||
assert_eq!(Priority::from_i32(-1), Priority::Low);
|
||||
assert_eq!(Priority::from_i32(i32::MIN), Priority::Low);
|
||||
assert_eq!(Priority::from_i32(i32::MAX), Priority::Low);
|
||||
}
|
||||
|
||||
// 与 as_str 对偶自洽:from_i32 的每个前端值 round-trip 后 as_str 不变
|
||||
#[test]
|
||||
fn priority_from_i32_roundtrip_consistent_with_as_str() {
|
||||
assert_eq!(Priority::from_i32(0).as_str(), "critical");
|
||||
assert_eq!(Priority::from_i32(1).as_str(), "high");
|
||||
assert_eq!(Priority::from_i32(2).as_str(), "medium");
|
||||
assert_eq!(Priority::from_i32(3).as_str(), "low");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user