use lz4::util;
#[test]
fn same_string_equal_returns_true() {
assert!(util::same_string("abc", "abc"));
}
#[test]
fn same_string_unequal_returns_false() {
assert!(!util::same_string("abc", "xyz"));
}
#[test]
fn same_string_both_empty_returns_true() {
assert!(util::same_string("", ""));
}
#[test]
fn same_string_one_empty_returns_false() {
assert!(!util::same_string("a", ""));
assert!(!util::same_string("", "b"));
}
#[test]
fn same_string_case_sensitive() {
assert!(!util::same_string("Hello", "hello"));
assert!(!util::same_string("HELLO", "hello"));
}
#[test]
fn same_string_unicode() {
assert!(util::same_string("héllo", "héllo"));
assert!(!util::same_string("héllo", "hello"));
}
#[test]
fn same_string_same_prefix_different_suffix() {
assert!(!util::same_string("abc", "abcd"));
assert!(!util::same_string("abcd", "abc"));
}
#[test]
fn sleep_millis_zero_does_not_block() {
let start = std::time::Instant::now();
util::sleep_millis(0);
let elapsed = start.elapsed();
assert!(
elapsed < std::time::Duration::from_millis(500),
"sleep_millis(0) took unexpectedly long: {elapsed:?}"
);
}
#[test]
fn sleep_secs_zero_does_not_block() {
let start = std::time::Instant::now();
util::sleep_secs(0);
let elapsed = start.elapsed();
assert!(
elapsed < std::time::Duration::from_millis(500),
"sleep_secs(0) took unexpectedly long: {elapsed:?}"
);
}
#[test]
fn sleep_millis_nonzero_waits_at_least_that_long() {
let start = std::time::Instant::now();
util::sleep_millis(50);
let elapsed = start.elapsed();
assert!(
elapsed >= std::time::Duration::from_millis(40), "sleep_millis(50) returned too early: {elapsed:?}"
);
}
#[test]
fn reexport_count_cores_accessible() {
assert!(util::count_cores() >= 1);
}
#[test]
fn reexport_is_reg_file_accessible() {
use std::path::Path;
assert!(!util::is_reg_file(Path::new(
"/nonexistent/__lz4_util_mod_test_reg__"
)));
}
#[test]
fn reexport_is_directory_accessible() {
use std::path::Path;
assert!(!util::is_directory(Path::new(
"/nonexistent/__lz4_util_mod_test_dir__"
)));
}
#[test]
fn reexport_get_file_size_accessible() {
use std::path::Path;
assert_eq!(
util::get_file_size(Path::new("/nonexistent/__lz4_util_mod_size__")),
0
);
}
#[test]
fn reexport_get_open_file_size_accessible() {
let file = tempfile::tempfile().unwrap();
assert_eq!(util::get_open_file_size(&file), 0);
}
#[test]
fn reexport_get_total_file_size_accessible() {
assert_eq!(util::get_total_file_size(&[]), 0);
}
#[test]
fn reexport_create_file_list_accessible() {
let list = util::create_file_list(&[]).unwrap();
assert!(list.is_empty());
}
#[cfg(unix)]
#[test]
fn reexport_is_reg_fd_accessible() {
assert!(!util::is_reg_fd(0));
}