1use log::info;
2
3pub fn build_string(
6 stanza_stack_record: &Vec<Vec<String>>,
7 config_line_stack: &Vec<String>,
8) -> String {
9 let mut new_string = String::from("set");
10
11 for vec in stanza_stack_record {
12 for string in vec {
13 new_string = new_string + " " + &string;
14 }
15 }
16 for string in config_line_stack {
17 new_string = new_string + " " + &string;
18 }
19
20 if new_string.ends_with(";") {
21 new_string.pop();
22 }
23 info!("config_line:\n{new_string}");
24 new_string
25}
26
27#[cfg(test)]
28mod test {
29 use super::build_string;
30
31 #[test]
32 fn test_build_string() {
33 let stanza_stack_record = vec![
34 vec![String::from("groups")],
35 vec![String::from("BLOCK-V6")],
36 vec![String::from("vlans")],
37 vec![String::from("<*>")],
38 vec![String::from("forwarding-options")],
39 vec![String::from("filter")],
40 ];
41 let config_line_stack = vec![String::from("input"), String::from("BLOCK-IPv6;")];
42 let result = build_string(&stanza_stack_record, &config_line_stack);
43 let expected = String::from(
44 "set groups BLOCK-V6 vlans <*> forwarding-options filter input BLOCK-IPv6",
45 );
46 assert_eq!(result, expected);
47 }
48}