use std::fs;
fn required_feature(stem: &str) -> Option<&'static str> {
match stem {
"feat_animimg" => Some("widget-animimg"),
"feat_arclabel" => Some("widget-arc-label"),
"feat_buttonmatrix" => Some("widget-buttonmatrix"),
"feat_calendar" => Some("widget-calendar"),
"feat_canvas" => Some("widget-canvas"),
"feat_chart" => Some("widget-chart"),
"feat_imagebutton" => Some("widget-imagebutton"),
"feat_keyboard" => Some("widget-keyboard"),
"feat_list" => Some("widget-list"),
"feat_menu" => Some("widget-menu"),
"feat_msgbox" => Some("widget-msgbox"),
"feat_spangroup" => Some("widget-spangroup"),
"feat_spinbox" => Some("widget-spinbox"),
"feat_spinner" => Some("widget-spinner"),
"feat_table" => Some("widget-table"),
"feat_tabview" => Some("widget-tabview"),
"feat_textarea" => Some("widget-textarea"),
"feat_tileview" => Some("widget-tileview"),
"feat_win" => Some("widget-win"),
_ => None,
}
}
fn feature_enabled(feature: &str) -> bool {
match feature {
"widget-animimg" => cfg!(feature = "widget-animimg"),
"widget-arc-label" => cfg!(feature = "widget-arc-label"),
"widget-buttonmatrix" => cfg!(feature = "widget-buttonmatrix"),
"widget-calendar" => cfg!(feature = "widget-calendar"),
"widget-canvas" => cfg!(feature = "widget-canvas"),
"widget-chart" => cfg!(feature = "widget-chart"),
"widget-imagebutton" => cfg!(feature = "widget-imagebutton"),
"widget-keyboard" => cfg!(feature = "widget-keyboard"),
"widget-list" => cfg!(feature = "widget-list"),
"widget-menu" => cfg!(feature = "widget-menu"),
"widget-msgbox" => cfg!(feature = "widget-msgbox"),
"widget-spangroup" => cfg!(feature = "widget-spangroup"),
"widget-spinbox" => cfg!(feature = "widget-spinbox"),
"widget-spinner" => cfg!(feature = "widget-spinner"),
"widget-table" => cfg!(feature = "widget-table"),
"widget-tabview" => cfg!(feature = "widget-tabview"),
"widget-textarea" => cfg!(feature = "widget-textarea"),
"widget-tileview" => cfg!(feature = "widget-tileview"),
"widget-win" => cfg!(feature = "widget-win"),
_ => false,
}
}
#[test]
fn snapshot_codegen() {
insta::glob!("fixtures/compile_check/*.yaml", |path| {
let stem = path.file_stem().and_then(|s| s.to_str()).expect("fixture path has stem");
if let Some(feat) = required_feature(stem)
&& !feature_enabled(feat)
{
return;
}
let yaml = fs::read_to_string(path).expect("fixture should be readable");
let code = oxiforge::generate_from_str(&yaml).expect("codegen should succeed");
insta::assert_snapshot!(code);
});
}