ntfsanitise 0.3.0

Sanitise filenames for use on NTFS filesystems
Documentation
use std::{ffi::OsString, os::unix::ffi::OsStringExt, path::PathBuf};

use crate::{PathBufExt, PathExt};

#[test]
fn clean_path() {
	let path = PathBuf::from("/mnt/the_street/our_house");
	assert!(path.is_clean());
	assert!(path.has_clean_file_name());
}

#[test]
fn dirty_path() {
	let path = PathBuf::from("/home/<punctuation_lover>/question marks?/colons: a treatise.txt");
	assert!(path.is_dirty());
	assert!(path.has_dirty_file_name());
}

#[test]
fn dirty_path_clean_filename() {
	let path = PathBuf::from("/opt/:)/smiley face.jpg");
	assert!(path.is_dirty());
	assert!(path.has_clean_file_name());
}

#[test]
fn sanitise_filename() {
	let mut path = PathBuf::from("/usr/local/share/examples/*tada!*.txt");
	assert!(path.has_dirty_file_name());
	assert_eq!(path.sanitise_filename("_"), Some(true));
	assert!(path.has_clean_file_name());
	assert!(path.is_clean());
	assert!(path.file_name().is_some_and(|file_name| file_name.to_str() == Some("_tada!_.txt")));
}

#[test]
fn sanitise_no_filename() {
	let mut path = PathBuf::from("/");
	assert!(path.file_name().is_none());
	assert_eq!(path.sanitise_filename("_"), None);
}

#[test]
fn sanitise_filename_invalid_utf8() {
	let mut path = PathBuf::from("/home/user/file.txt");
	path.set_file_name(OsString::from_vec(b"\xFF".to_vec()));
	assert_eq!(path.sanitise_filename("_"), Some(false));
}