| 159 | |
| 160 | #[test] |
| 161 | fn test_template() -> Result<()> { |
| 162 | let temp_dir = tempfile::tempdir()?; |
| 163 | let file1_path = temp_dir.path().join("a.toml"); |
| 164 | let file2_path = temp_dir.path().join("dyn.toml"); |
| 165 | let mut file1 = std::fs::File::create(&file1_path)?; |
| 166 | write!( |
| 167 | file1, |
| 168 | "{}", |
| 169 | r#" |
| 170 | include=[] |
| 171 | {{ a = 1 -}} |
| 172 | {{ b = "string" -}} |
| 173 | a={{a}} |
| 174 | b="{{b}}" |
| 175 | c = [{% for i in List %} {{- i+1 -}}, {% end for %}] |
| 176 | d = [{% for i in List %} {{- i*2 -}}, {% end for %}] |
| 177 | e={a={{a}}}"# |
| 178 | ) |
| 179 | .unwrap(); |
| 180 | let mut file2 = std::fs::File::create(&file2_path)?; |
| 181 | write!(file2, "List=[1,2,3]")?; |
| 182 | |
| 183 | let config: Config = Parser::from_file(&file1_path, Some(&file2_path))?; |
| 184 | |
| 185 | assert_eq!(config.a, 1); |
| 186 | assert_eq!(config.b, "string"); |
| 187 | assert_eq!(config.c, vec![2, 3, 4]); |
| 188 | assert!(config.d.contains(&2)); |
| 189 | assert!(config.d.contains(&4)); |
| 190 | assert!(config.d.contains(&6)); |
| 191 | |
| 192 | assert_eq!(config.e.len(), 1); |
| 193 | assert_eq!(config.e["a"], 1); |
| 194 | Ok(()) |
| 195 | } |
| 196 | } |