ecformat 0.2.0

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

//! Module for helper function only in use by the Unit Tests for the indentation module.

use ec4rs::{
    PropertyKey,
    property::{IndentSize, IndentStyle, TabWidth},
    rawvalue::RawValue,
};

use super::super::IndentationHandler;

/// Build the handler using the properties which are some.
pub fn build_indentation_handler(
    indent_style: Option<IndentStyle>,
    indent_size: Option<IndentSize>,
    tab_width: Option<TabWidth>,
) -> IndentationHandler {
    let mut properties = ec4rs::Properties::new();

    add_property_option(&mut properties, indent_style);
    add_property_option(&mut properties, indent_size);
    add_property_option(&mut properties, tab_width);

    IndentationHandler::build(&properties)
        .expect("Every test case lead to properties, which needs to be handled")
}

/// Adds one property if it is some to the given properties' struct.
fn add_property_option<P: PropertyKey + Into<RawValue>>(
    properties: &mut ec4rs::Properties,
    property: Option<P>,
) {
    if let Some(value) = property {
        properties.insert::<P>(value);
    }
}