| 1 |
use rstest::rstest; |
| 2 |
use time::format_description::{BorrowedFormatItem, Component, OwnedFormatItem, modifier}; |
| 3 |
|
| 4 |
#[rstest] |
| 5 |
fn borrowed_format_item_component_conversions() { |
| 6 |
let component = Component::CalendarYearFullExtendedRange( |
| 7 |
modifier::CalendarYearFullExtendedRange::default(), |
| 8 |
); |
| 9 |
let item = BorrowedFormatItem::from(component); |
| 10 |
assert!(matches!(item, BorrowedFormatItem::Component(inner) if inner == component)); |
| 11 |
assert_eq!(Component::try_from(item), Ok(component)); |
| 12 |
assert!(Component::try_from(BorrowedFormatItem::StringLiteral("")).is_err()); |
| 13 |
assert!(<&[BorrowedFormatItem<'_>]>::try_from(BorrowedFormatItem::StringLiteral("")).is_err()); |
| 14 |
} |
| 15 |
|
| 16 |
#[rstest] |
| 17 |
fn borrowed_format_item_compound_conversions() { |
| 18 |
let compound = [BorrowedFormatItem::StringLiteral("")].as_slice(); |
| 19 |
let item = BorrowedFormatItem::from(compound); |
| 20 |
assert!(matches!(item, BorrowedFormatItem::Compound(inner) if inner == compound)); |
| 21 |
assert_eq!(<&[BorrowedFormatItem<'_>]>::try_from(item), Ok(compound)); |
| 22 |
} |
| 23 |
|
| 24 |
#[rstest] |
| 25 |
fn borrowed_format_item_equality() { |
| 26 |
let component = Component::CalendarYearFullExtendedRange( |
| 27 |
modifier::CalendarYearFullExtendedRange::default(), |
| 28 |
); |
| 29 |
let compound = [BorrowedFormatItem::StringLiteral("")].as_slice(); |
| 30 |
let component_item = BorrowedFormatItem::from(component); |
| 31 |
let compound_item = BorrowedFormatItem::from(compound); |
| 32 |
|
| 33 |
assert_eq!(component, component_item); |
| 34 |
assert_eq!(component_item, component); |
| 35 |
assert_eq!(compound, compound_item); |
| 36 |
assert_eq!(compound_item, compound); |
| 37 |
} |
| 38 |
|
| 39 |
#[rstest] |
| 40 |
fn owned_format_item_component_conversions() { |
| 41 |
let component = Component::CalendarYearFullExtendedRange( |
| 42 |
modifier::CalendarYearFullExtendedRange::default(), |
| 43 |
); |
| 44 |
let item = OwnedFormatItem::from(component); |
| 45 |
assert!(matches!(item, OwnedFormatItem::Component(inner) if inner == component)); |
| 46 |
assert_eq!(Component::try_from(item), Ok(component)); |
| 47 |
assert!( |
| 48 |
Component::try_from(OwnedFormatItem::StringLiteral( |
| 49 |
"".to_owned().into_boxed_str() |
| 50 |
)) |
| 51 |
.is_err() |
| 52 |
); |
| 53 |
assert!( |
| 54 |
Vec::<OwnedFormatItem>::try_from(OwnedFormatItem::StringLiteral( |
| 55 |
"".to_owned().into_boxed_str() |
| 56 |
)) |
| 57 |
.is_err() |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
#[rstest] |
| 62 |
fn owned_format_item_compound_conversions() { |
| 63 |
let compound = vec![OwnedFormatItem::StringLiteral( |
| 64 |
"".to_owned().into_boxed_str(), |
| 65 |
)]; |
| 66 |
let item = OwnedFormatItem::from(compound.clone()); |
| 67 |
assert!(matches!(item.clone(), OwnedFormatItem::Compound(inner) if inner.to_vec() == compound)); |
| 68 |
assert_eq!(Vec::<OwnedFormatItem>::try_from(item), Ok(compound)); |
| 69 |
} |
| 70 |
|
| 71 |
#[rstest] |
| 72 |
fn owned_format_item_equality() { |
| 73 |
let component = Component::CalendarYearFullExtendedRange( |
| 74 |
modifier::CalendarYearFullExtendedRange::default(), |
| 75 |
); |
| 76 |
let compound = OwnedFormatItem::from([BorrowedFormatItem::StringLiteral("")].as_slice()); |
| 77 |
let component_item = OwnedFormatItem::from(component); |
| 78 |
|
| 79 |
assert_eq!(component, component_item); |
| 80 |
assert_eq!(component_item, component); |
| 81 |
assert_eq!( |
| 82 |
compound, |
| 83 |
[OwnedFormatItem::StringLiteral( |
| 84 |
"".to_owned().into_boxed_str() |
| 85 |
)] |
| 86 |
.as_slice() |
| 87 |
); |
| 88 |
assert_eq!( |
| 89 |
[OwnedFormatItem::StringLiteral( |
| 90 |
"".to_owned().into_boxed_str() |
| 91 |
)] |
| 92 |
.as_slice(), |
| 93 |
compound |
| 94 |
); |
| 95 |
} |