Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add tests for const fn #241

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ mod tests {
);
}

#[test]
const fn kind_dos_date_time_range_error_is_const_fn() {
const _: DosDateTimeRangeErrorKind =
DosDateTimeRangeError::new(DosDateTimeRangeErrorKind::Negative).kind();
}

#[test]
fn display_dos_date_time_range_error() {
assert_eq!(
Expand Down Expand Up @@ -492,6 +498,12 @@ mod tests {
);
}

#[test]
const fn kind_file_time_range_error_is_const_fn() {
const _: FileTimeRangeErrorKind =
FileTimeRangeError::new(FileTimeRangeErrorKind::Negative).kind();
}

#[test]
fn display_file_time_range_error() {
assert_eq!(
Expand Down
30 changes: 30 additions & 0 deletions src/file_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,23 @@ mod tests {
assert_eq!(FileTime::new(u64::MAX), FileTime::MAX);
}

#[test]
const fn new_is_const_fn() {
const _: FileTime = FileTime::new(u64::MIN);
}

#[test]
fn to_raw() {
assert_eq!(FileTime::NT_TIME_EPOCH.to_raw(), u64::MIN);
assert_eq!(FileTime::UNIX_EPOCH.to_raw(), 116_444_736_000_000_000);
assert_eq!(FileTime::MAX.to_raw(), u64::MAX);
}

#[test]
const fn to_raw_is_const_fn() {
const _: u64 = FileTime::NT_TIME_EPOCH.to_raw();
}

#[test]
fn to_be_bytes() {
assert_eq!(FileTime::NT_TIME_EPOCH.to_be_bytes(), [u8::MIN; 8]);
Expand All @@ -338,6 +348,11 @@ mod tests {
prop_assert_eq!(ft.to_be_bytes(), ft.to_raw().to_be_bytes());
}

#[test]
const fn to_be_bytes_is_const_fn() {
const _: [u8; 8] = FileTime::NT_TIME_EPOCH.to_be_bytes();
}

#[test]
fn to_le_bytes() {
assert_eq!(FileTime::NT_TIME_EPOCH.to_le_bytes(), [u8::MIN; 8]);
Expand All @@ -356,6 +371,11 @@ mod tests {
prop_assert_eq!(ft.to_le_bytes(), ft.to_raw().to_le_bytes());
}

#[test]
const fn to_le_bytes_is_const_fn() {
const _: [u8; 8] = FileTime::NT_TIME_EPOCH.to_le_bytes();
}

#[test]
fn from_be_bytes() {
assert_eq!(
Expand All @@ -380,6 +400,11 @@ mod tests {
);
}

#[test]
const fn from_be_bytes_is_const_fn() {
const _: FileTime = FileTime::from_be_bytes([u8::MIN; 8]);
}

#[test]
fn from_le_bytes() {
assert_eq!(
Expand All @@ -404,6 +429,11 @@ mod tests {
);
}

#[test]
const fn from_le_bytes_is_const_fn() {
const _: FileTime = FileTime::from_le_bytes([u8::MIN; 8]);
}

#[test]
fn default() {
assert_eq!(FileTime::default(), FileTime::NT_TIME_EPOCH);
Expand Down