use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Ods {
pub raw: u32,
}
impl Ods {
pub const fn new(raw: u32) -> Self {
Self { raw }
}
pub fn client_family(&self) -> &'static str {
match self.raw {
16 => "Notes 1.x - 2.x",
17 => "Notes 3.x",
20 => "Notes 4.x",
41 => "Notes 5.x",
43 => "Notes 6.x, 7.x",
48 => "Notes 8.0",
51 => "Notes 8.5, 9.0",
52 => "Notes 9.0.1",
53 => "Notes 10, 11, 12, 14 (HCL)",
_ => "unknown ODS",
}
}
pub fn is_supported_for_enumeration(&self) -> bool {
self.raw >= 20 && self.raw <= 53
}
pub fn is_modern_64bit_positions(&self) -> bool {
self.raw >= 53
}
}
impl fmt::Display for Ods {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ODS {} ({})", self.raw, self.client_family())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn maps_modern_hcl_ods_53() {
let ods = Ods::new(53);
assert!(ods.client_family().contains("HCL"));
assert!(ods.is_supported_for_enumeration());
assert!(ods.is_modern_64bit_positions());
}
#[test]
fn maps_classic_ods_43_notes_6_7() {
let ods = Ods::new(43);
assert!(ods.client_family().contains("6.x"));
assert!(ods.is_supported_for_enumeration());
assert!(!ods.is_modern_64bit_positions());
}
#[test]
fn refuses_pre_notes_4_ods() {
for v in [16, 17, 18, 19] {
assert!(!Ods::new(v).is_supported_for_enumeration());
}
}
#[test]
fn unknown_ods_falls_back_cleanly() {
let ods = Ods::new(999);
assert_eq!(ods.client_family(), "unknown ODS");
assert!(!ods.is_supported_for_enumeration());
}
#[test]
fn display_includes_raw_and_family() {
let s = format!("{}", Ods::new(51));
assert!(s.contains("51"));
assert!(s.contains("8.5"));
}
}