use std::io::Write;
use ec4rs::property::Charset;
use rstest::rstest;
use tempfile::NamedTempFile;
use super::super::{overwrite_file, read_file};
#[rstest]
fn test_overwrite_file_special_characters(
#[values(
Charset::Utf8,
Charset::Latin1,
Charset::Utf16Le,
Charset::Utf16Be,
Charset::Utf8Bom
)]
charset: Charset,
) {
let old_content = "Something to overwrite";
let new_content = "Some special characters: Ä ° ß ² € ó";
let mut test_file = NamedTempFile::new().expect("Tempfile needs to be possible");
test_file
.as_file_mut()
.write_all(old_content.as_bytes())
.expect("Tempfile needs to be accessible");
overwrite_file(test_file.path(), &charset, new_content)
.expect("Tempfile needs to be overwritable");
let read_content =
read_file(test_file.path(), &charset).expect("Tempfile needs to be readable");
assert!(
!read_content.contains(old_content),
"The old content have to be overwritten."
);
assert_eq!(
new_content, read_content,
"The read content needs to be the written one"
);
}