Coverage Report

Created: 2025-08-13 21:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/home/a220/proj/radnelac/src/display/roman.rs
Line
Count
Source
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5
use crate::calendar::Roman;
6
use crate::calendar::RomanMonthlyEvent;
7
use crate::display::private::get_dict;
8
use crate::display::text::prelude::Language;
9
use numerals;
10
use std::fmt;
11
12
impl fmt::Display for Roman {
13
5
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14
5
        let dict = get_dict(Language::EN)
15
5
            .roman
16
5
            .as_ref()
17
5
            .expect("Known to exist");
18
19
5
        let event_name = match self.event() {
20
2
            RomanMonthlyEvent::Kalends => dict.kalends,
21
1
            RomanMonthlyEvent::Nones => dict.nones,
22
2
            RomanMonthlyEvent::Ides => dict.ides,
23
        };
24
25
5
        let months: [&str; 12] = [
26
5
            dict.january,
27
5
            dict.february,
28
5
            dict.march,
29
5
            dict.april,
30
5
            dict.may,
31
5
            dict.june,
32
5
            dict.july,
33
5
            dict.august,
34
5
            dict.september,
35
5
            dict.october,
36
5
            dict.november,
37
5
            dict.december,
38
5
        ];
39
5
        let month_name = months[self.month() as usize - 1];
40
5
        let year = Roman::auc_year_from_julian(self.year());
41
42
5
        if self.count().get() == 1 {
43
1
            write!(
44
1
                f,
45
1
                "{} {} {}, {} {}",
46
                event_name, dict.x_of_y, month_name, year, dict.after_auc_full
47
            )
48
4
        } else if self.count().get() == 2 {
49
2
            write!(
50
2
                f,
51
2
                "{} {} {}, {} {}",
52
                dict.pridie, event_name, month_name, year, dict.after_auc_full
53
            )
54
        } else {
55
2
            let bissextum = if self.leap() { 
dict.bissextum1
} else {
""1
};
56
2
            let bissextum_space = if self.leap() { 
" "1
} else {
""1
};
57
2
            write!(
58
2
                f,
59
2
                "{} {}{}{:X} {} {}, {} {}",
60
                dict.ante_diem,
61
                bissextum,
62
                bissextum_space,
63
2
                numerals::roman::Roman::from(self.count().get() as i16),
64
                event_name,
65
                month_name,
66
                year,
67
                dict.after_auc_full
68
            )
69
        }
70
5
    }
71
}
72
73
#[cfg(test)]
74
mod tests {
75
    use super::*;
76
    use crate::calendar::CommonDate;
77
    use crate::calendar::Julian;
78
    use crate::calendar::ToFromCommonDate;
79
    use crate::day_count::FromFixed;
80
    use crate::day_count::ToFixed;
81
82
    #[test]
83
1
    fn second_sixth_day_before_kalends_of_march() {
84
1
        let j24 = Julian::try_from_common_date(CommonDate::new(4, 2, 24)).unwrap();
85
1
        let j25 = Julian::try_from_common_date(CommonDate::new(4, 2, 25)).unwrap();
86
1
        let f24 = j24.to_fixed();
87
1
        let f25 = j25.to_fixed();
88
1
        let r24s = Roman::from_fixed(f24).to_string();
89
1
        let r25s = Roman::from_fixed(f25).to_string();
90
1
        assert!(r24s.starts_with("ante diem VI Kalends March"), "{}", r24s);
91
1
        assert!(
92
1
            r25s.starts_with("ante diem bissextum VI Kalends March"),
93
            "{}",
94
            r25s
95
        );
96
1
    }
97
98
    #[test]
99
1
    fn pridie_nones_of_march() {
100
1
        let j = Julian::try_from_common_date(CommonDate::new(-44, 3, 6)).unwrap();
101
1
        let f = j.to_fixed();
102
1
        let r = Roman::from_fixed(f);
103
1
        assert!(r.to_string().starts_with("pridie Nones March"));
104
1
    }
105
106
    #[test]
107
1
    fn pridie_ides_of_march() {
108
1
        let j = Julian::try_from_common_date(CommonDate::new(-44, 3, 14)).unwrap();
109
1
        let f = j.to_fixed();
110
1
        let r = Roman::from_fixed(f);
111
1
        assert!(r.to_string().starts_with("pridie Ides March"));
112
1
    }
113
114
    #[test]
115
1
    fn ides_of_march() {
116
1
        let j = Julian::try_from_common_date(CommonDate::new(-44, 3, 15)).unwrap();
117
1
        let f = j.to_fixed();
118
1
        let r = Roman::from_fixed(f);
119
1
        assert!(r.to_string().starts_with("Ides of March"));
120
1
    }
121
}