Skip to main content

easypdf_markdown/
ocr_policy.rs

1//! OCR 回退策略。
2
3/// OCR 回退策略。
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum OcrPolicy {
7    /// 不执行 OCR。
8    #[default]
9    Disabled,
10    /// 仅在页面缺少原生文本时尝试 OCR。
11    Auto,
12}
13
14#[cfg(test)]
15#[allow(clippy::uninlined_format_args, clippy::float_cmp)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn default_is_disabled() {
21        assert_eq!(OcrPolicy::default(), OcrPolicy::Disabled);
22    }
23
24    #[test]
25    fn debug_format() {
26        assert_eq!(format!("{:?}", OcrPolicy::Disabled), "Disabled");
27        assert_eq!(format!("{:?}", OcrPolicy::Auto), "Auto");
28    }
29
30    #[test]
31    fn clone_copy() {
32        let p = OcrPolicy::Auto;
33        let copied = p;
34        assert_eq!(p, copied);
35    }
36
37    #[test]
38    fn partial_eq() {
39        assert_eq!(OcrPolicy::Disabled, OcrPolicy::Disabled);
40        assert_ne!(OcrPolicy::Disabled, OcrPolicy::Auto);
41    }
42}