Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaggededgedjustice committed Apr 9, 2023
1 parent 97c48e9 commit db62b24
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,10 @@ mod tests {
date_sub -= TimeDelta::days(5);
assert_eq!(date_sub, date - TimeDelta::days(5));
}

#[test]
fn test_invalid_format() {
let result = Utc::today().format("%");
assert!(result.is_err(), "Invalid format string should be format error")
}
}
9 changes: 9 additions & 0 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,3 +1341,12 @@ fn test_decodable_json<FUtc, FFixed, FLocal, E>(
fn test_invalid_format() {
assert!(Utc::now().format("%").is_err());
}

#[test]
#[cfg(feature = "unstable-locales")]
fn test_invalid_format_localized() {
assert!(
Utc::now().format_localized("%", Locale::de_DE).is_err(),
"Invalid format string should be format error"
)
}
9 changes: 9 additions & 0 deletions src/format/strftime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,12 @@ fn test_strftime_docs_localized() {
assert_eq!(nd.format_localized("%F", Locale::de_DE).unwrap().to_string(), "2001-07-08");
assert_eq!(nd.format_localized("%v", Locale::de_DE).unwrap().to_string(), " 8-Jul-2001");
}

#[cfg(feature = "unstable-locales")]
#[test]
fn test_strftime_with_locale() {
assert!(
StrftimeItems::new_with_locale("%", Locale::de_DE).is_err(),
"Invalid format string should be format error"
)
}
8 changes: 8 additions & 0 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3019,4 +3019,12 @@ mod tests {
}
}
}

#[test]
fn test_format() {
assert!(
NaiveDate::from_ymd_opt(2023, 4, 9).unwrap().format("%").is_err(),
"Invalid format string should be format error"
)
}
}
13 changes: 13 additions & 0 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,3 +1921,16 @@ where
assert!(from_str(r#"{"date":{"ymdf":20},"time":{"secs":0,"frac":0}}"#).is_err());
assert!(from_str(r#"null"#).is_err());
}

#[test]
fn test_format() {
assert!(
NaiveDate::from_ymd_opt(-1, 12, 31)
.unwrap()
.and_hms_nano_opt(23, 59, 59, 7)
.unwrap()
.format("%")
.is_err(),
"Invalid format string should be format error"
)
}
8 changes: 8 additions & 0 deletions src/naive/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,3 +1381,11 @@ where
assert!(from_str(r#"{"secs":0,"frac":0}"#).is_err());
assert!(from_str(r#"null"#).is_err());
}

#[test]
fn test_format() {
assert!(
NaiveTime::from_hms_opt(1, 2, 3).unwrap().format("%").is_err(),
"Invalid format string should be format error"
)
}

0 comments on commit db62b24

Please sign in to comment.