use crate::{child_block, has_leaf};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ConfigurationInput {
pub json_reorder_list_keys: bool,
}
pub(super) fn parse_configuration(configuration: &ConfigLine) -> ConfigurationInput {
let json = child_block(configuration, "input")
.and_then(|input| child_block(input, "format"))
.and_then(|format| child_block(format, "json"));
ConfigurationInput {
json_reorder_list_keys: json.is_some_and(|json| has_leaf(json, "reorder-list-keys")),
}
}
#[cfg(test)]
mod tests {
use crate::system::system;
use asterust::config::juniper;
#[test]
fn extracts_the_json_input_format() {
let configuration = system(&juniper::parse_braces(
"system {\n configuration {\n input {\n format {\n json {\n reorder-list-keys;\n }\n }\n }\n }\n}\n",
))
.unwrap()
.configuration
.unwrap();
assert!(configuration.json_reorder_list_keys);
}
#[test]
fn no_configuration_is_none() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert!(system.configuration.is_none());
}
}