MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / test_template

Function test_template

flow-rs/src/config/parser.rs:161–195  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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#"
170include=[]
171{{ a = 1 -}}
172{{ b = "string" -}}
173a={{a}}
174b="{{b}}"
175c = [{% for i in List %} {{- i+1 -}}, {% end for %}]
176d = [{% for i in List %} {{- i*2 -}}, {% end for %}]
177e={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}

Callers

nothing calls this directly

Calls 1

createFunction · 0.85

Tested by

no test coverage detected