ecformat 0.1.1

command line tool to keep files correct in respect of your EditorConfig
Documentation
// SPDX-FileCopyrightText: Contributors to ecformat project <https://codeberg.org/BaumiCoder/ecformat>
//
// SPDX-License-Identifier: BlueOak-1.0.0

//! Tests for the function [`overwritte_file`]

use std::io::Write;

use ec4rs::property::Charset;
use rstest::rstest;
use tempfile::NamedTempFile;

use super::super::{overwrite_file, read_file};

/// Overwrites a temp file incl. some special characters and checks that content is correct.
#[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"
    );
}