use super::cargo::emit_cargo_toml;
use crate::core::config::ResolvedCrateConfig;
use crate::core::config::languages::DartConfig;
use crate::core::ir::ApiSurface;
#[test]
fn cargo_toml_excludes_named_feature_from_core_dep_line_but_keeps_others() {
let api = ApiSurface::default();
let config = ResolvedCrateConfig {
name: "sample-lib".to_string(),
dart: Some(DartConfig {
features: Some(vec!["native-http".to_string(), "wasm-http".to_string()]),
excluded_default_features: vec!["native-http".to_string()],
..Default::default()
}),
..Default::default()
};
let file = emit_cargo_toml("packages/dart/rust", &api, &config, "sample_lib");
let core_dep_line = file
.content
.lines()
.find(|l| l.trim_start().starts_with("sample_lib ="))
.expect("core dependency line must be emitted");
assert!(
!core_dep_line.contains("native-http"),
"excluded_default_features must drop the name from the core dependency's own explicit \
features = [...] line, not just the wrapper's default array:\n{core_dep_line}"
);
assert!(
core_dep_line.contains("wasm-http"),
"a feature nobody excluded must still be forwarded to the core dependency line:\n{core_dep_line}"
);
toml::from_str::<toml::Value>(&file.content).expect("generated Cargo.toml must be valid TOML");
}
#[test]
fn cargo_toml_forwards_excluded_feature_not_referenced_by_any_cfg_attribute() {
let api = ApiSurface::default();
let config = ResolvedCrateConfig {
name: "sample-lib".to_string(),
dart: Some(DartConfig {
excluded_default_features: vec!["heic".to_string()],
..Default::default()
}),
..Default::default()
};
let file = emit_cargo_toml("packages/dart/rust", &api, &config, "sample_lib");
assert!(
file.content.contains("[features]"),
"a config-only excluded_default_features name must still produce a [features] table:\n{}",
file.content
);
assert!(
file.content.contains(r#"heic = ["sample_lib/heic"]"#),
"a config-only excluded_default_features name (not referenced by any #[cfg(feature = ...)] \
in the API surface) must still get a forwarding entry so `cargo build --features heic` \
keeps working:\n{}",
file.content
);
let default_line = file
.content
.lines()
.find(|l| l.starts_with("default = ["))
.expect("default = [...] line must be emitted");
assert!(
!default_line.contains("\"heic\""),
"default = [...] must NOT contain excluded `heic`; got: {default_line}"
);
toml::from_str::<toml::Value>(&file.content).expect("generated Cargo.toml must be valid TOML");
}