MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / from_toml

Function from_toml

crates/cli-flags/src/lib.rs:1274–1389  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1272
1273 #[test]
1274 fn from_toml() {
1275 // empty toml
1276 let empty_toml = "";
1277 let mut common_options: CommonOptions = toml::from_str(empty_toml).unwrap();
1278 common_options.config(None).unwrap();
1279
1280 // basic toml
1281 let basic_toml = r#"
1282 [optimize]
1283 [codegen]
1284 [debug]
1285 [wasm]
1286 [wasi]
1287 [record]
1288 "#;
1289 let mut common_options: CommonOptions = toml::from_str(basic_toml).unwrap();
1290 common_options.config(None).unwrap();
1291
1292 // toml with custom deserialization to match CLI flag parsing
1293 for (opt_value, expected) in [
1294 ("0", Some(OptLevel::None)),
1295 ("1", Some(OptLevel::Speed)),
1296 ("2", Some(OptLevel::Speed)),
1297 ("\"s\"", Some(OptLevel::SpeedAndSize)),
1298 ("\"hello\"", None), // should fail
1299 ("3", None), // should fail
1300 ] {
1301 let toml = format!(
1302 r#"
1303 [optimize]
1304 opt-level = {opt_value}
1305 "#,
1306 );
1307 let parsed_opt_level = toml::from_str::<CommonOptions>(&toml)
1308 .ok()
1309 .and_then(|common_options| common_options.opts.opt_level);
1310
1311 assert_eq!(
1312 parsed_opt_level, expected,
1313 "Mismatch for input '{opt_value}'. Parsed: {parsed_opt_level:?}, Expected: {expected:?}"
1314 );
1315 }
1316
1317 // Regalloc algorithm
1318 for (regalloc_value, expected) in [
1319 ("\"backtracking\"", Some(RegallocAlgorithm::Backtracking)),
1320 ("\"single-pass\"", Some(RegallocAlgorithm::SinglePass)),
1321 ("\"hello\"", None), // should fail
1322 ("3", None), // should fail
1323 ("true", None), // should fail
1324 ] {
1325 let toml = format!(
1326 r#"
1327 [optimize]
1328 regalloc-algorithm = {regalloc_value}
1329 "#,
1330 );
1331 let parsed_regalloc_algorithm = toml::from_str::<CommonOptions>(&toml)

Callers

nothing calls this directly

Calls 3

unwrapMethod · 0.45
configMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected