Skip to content

Commit

Permalink
Add unit test for uncovered regions (#1149)
Browse files Browse the repository at this point in the history
Co-authored-by: cxworks <cxworks@qq.com>
  • Loading branch information
2 people authored and pitdicker committed Jul 25, 2023
1 parent c181151 commit 0228e5e
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/format/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,12 @@ enum CommentState {

#[cfg(test)]
mod tests {
use super::comment_2822;
use super::{
comment_2822, nanosecond, nanosecond_fixed, short_or_long_month0, short_or_long_weekday,
space, timezone_offset_2822,
};
use crate::format::{INVALID, TOO_SHORT};
use crate::Weekday;

#[test]
fn test_rfc2822_comments() {
Expand Down Expand Up @@ -402,4 +406,42 @@ mod tests {
);
}
}

#[test]
fn test_timezone_offset_2822() {
assert_eq!(timezone_offset_2822("cSt").unwrap(), ("", Some(-21600)));
assert_eq!(timezone_offset_2822("pSt").unwrap(), ("", Some(-28800)));
assert_eq!(timezone_offset_2822("mSt").unwrap(), ("", Some(-25200)));
assert_eq!(timezone_offset_2822("-1551").unwrap(), ("", Some(-57060)));
assert_eq!(timezone_offset_2822("Gp").unwrap(), ("", None));
}

#[test]
fn test_short_or_long_month0() {
assert_eq!(short_or_long_month0("JUn").unwrap(), ("", 5));
assert_eq!(short_or_long_month0("mAy").unwrap(), ("", 4));
assert_eq!(short_or_long_month0("AuG").unwrap(), ("", 7));
assert_eq!(short_or_long_month0("Aprâ").unwrap(), ("â", 3));
assert_eq!(short_or_long_month0("JUl").unwrap(), ("", 6));
assert_eq!(short_or_long_month0("mAr").unwrap(), ("", 2));
assert_eq!(short_or_long_month0("Jan").unwrap(), ("", 0));
}

#[test]
fn test_short_or_long_weekday() {
assert_eq!(short_or_long_weekday("sAtu").unwrap(), ("u", Weekday::Sat));
assert_eq!(short_or_long_weekday("thu").unwrap(), ("", Weekday::Thu));
}

#[test]
fn test_nanosecond_fixed() {
assert_eq!(nanosecond_fixed("", 0usize).unwrap(), ("", 0));
assert!(nanosecond_fixed("", 1usize).is_err());
}

#[test]
fn test_nanosecond() {
assert_eq!(nanosecond("2Ù").unwrap(), ("Ù", 200000000));
assert_eq!(nanosecond("8").unwrap(), ("", 800000000));
}
}

0 comments on commit 0228e5e

Please sign in to comment.