| 1 |
#![cfg(all( // require `--all-features` to be passed |
| 2 |
feature = "default", |
| 3 |
feature = "alloc", |
| 4 |
feature = "formatting", |
| 5 |
feature = "large-dates", |
| 6 |
feature = "local-offset", |
| 7 |
feature = "macros", |
| 8 |
feature = "parsing", |
| 9 |
feature = "quickcheck", |
| 10 |
feature = "serde-human-readable", |
| 11 |
feature = "serde-well-known", |
| 12 |
feature = "std", |
| 13 |
feature = "rand", |
| 14 |
feature = "serde", |
| 15 |
))] |
| 16 |
#![allow( |
| 17 |
clippy::cognitive_complexity, |
| 18 |
reason = "many tests in one function is okay" |
| 19 |
)] |
| 20 |
#![allow(clippy::std_instead_of_core, reason = "irrelevant for tests")] |
| 21 |
|
| 22 |
//! Tests for internal details. |
| 23 |
//! |
| 24 |
//! This module should only be used when it is not possible to test the implementation in a |
| 25 |
//! reasonable manner externally. |
| 26 |
|
| 27 |
use std::format; |
| 28 |
|
| 29 |
use rstest::rstest; |
| 30 |
|
| 31 |
use crate::ext::DigitCount; |
| 32 |
use crate::parsing::combinator::rfc::iso8601; |
| 33 |
use crate::{format_description, parsing, signed_duration}; |
| 34 |
|
| 35 |
#[rstest] |
| 36 |
#[case(1, 1)] |
| 37 |
#[case(9, 1)] |
| 38 |
#[case(10, 2)] |
| 39 |
#[case(99, 2)] |
| 40 |
#[case(100, 3)] |
| 41 |
fn digit_count_u8(#[case] input: u8, #[case] expected: u8) { |
| 42 |
assert_eq!(input.num_digits(), expected); |
| 43 |
} |
| 44 |
|
| 45 |
#[rstest] |
| 46 |
#[case(1, 1)] |
| 47 |
#[case(9, 1)] |
| 48 |
#[case(10, 2)] |
| 49 |
#[case(99, 2)] |
| 50 |
#[case(100, 3)] |
| 51 |
#[case(999, 3)] |
| 52 |
#[case(1_000, 4)] |
| 53 |
#[case(9_999, 4)] |
| 54 |
#[case(10_000, 5)] |
| 55 |
fn digit_count_u16(#[case] input: u16, #[case] expected: u8) { |
| 56 |
assert_eq!(input.num_digits(), expected); |
| 57 |
} |
| 58 |
|
| 59 |
#[rstest] |
| 60 |
#[case(1, 1)] |
| 61 |
#[case(9, 1)] |
| 62 |
#[case(10, 2)] |
| 63 |
#[case(99, 2)] |
| 64 |
#[case(100, 3)] |
| 65 |
#[case(999_999, 6)] |
| 66 |
#[case(1_000_000, 7)] |
| 67 |
#[case(9_999_999, 7)] |
| 68 |
#[case(10_000_000, 8)] |
| 69 |
#[case(99_999_999, 8)] |
| 70 |
#[case(100_000_000, 9)] |
| 71 |
#[case(999_999_999, 9)] |
| 72 |
#[case(1_000_000_000, 10)] |
| 73 |
fn digit_count_u32(#[case] input: u32, #[case] expected: u8) { |
| 74 |
assert_eq!(input.num_digits(), expected); |
| 75 |
} |
| 76 |
|
| 77 |
#[rstest] |
| 78 |
#[case(signed_duration::Padding::Optimize)] |
| 79 |
#[case(parsing::ParsedItem(b"", 0))] |
| 80 |
#[case(format_description::Period::Am)] |
| 81 |
#[case(iso8601::ExtendedKind::Basic)] |
| 82 |
fn debug(#[case] input: impl std::fmt::Debug) { |
| 83 |
drop(format!("{input:?}")); |
| 84 |
} |
| 85 |
|
| 86 |
#[rstest] |
| 87 |
#[case(format_description::Period::Am)] |
| 88 |
#[case(crate::time::Padding::Optimize)] |
| 89 |
fn clone(#[case] input: impl Clone + PartialEq) { |
| 90 |
assert!(input.clone() == input); |
| 91 |
} |
| 92 |
|
| 93 |
#[rstest] |
| 94 |
#[expect(clippy::clone_on_copy, reason = "purpose of the test")] |
| 95 |
fn clone_matches() { |
| 96 |
assert!(matches!( |
| 97 |
iso8601::ExtendedKind::Basic.clone(), |
| 98 |
iso8601::ExtendedKind::Basic |
| 99 |
)); |
| 100 |
} |
| 101 |
|
| 102 |
#[rstest] |
| 103 |
fn parsing_internals() { |
| 104 |
assert!( |
| 105 |
parsing::ParsedItem(b"", ()) |
| 106 |
.flat_map(|_| None::<()>) |
| 107 |
.is_none() |
| 108 |
); |
| 109 |
} |