use super::*;
fn resolve_lang_c(config: &ResolvedCrateConfig) -> Vec<Language> {
let lang_filter: Option<Vec<String>> = Some(vec!["c".to_string()]);
let rendered = crate::bin_cli::helpers::resolve_doc_languages(config, lang_filter.as_deref()).unwrap();
assert_eq!(
rendered,
vec![Language::C],
"sanity check: `--lang c` must resolve to exactly [C], the path this test exercises"
);
rendered
}
fn resolve_lang_jni(config: &ResolvedCrateConfig) -> Vec<Language> {
let lang_filter: Option<Vec<String>> = Some(vec!["jni".to_string()]);
let rendered = crate::bin_cli::helpers::resolve_doc_languages(config, lang_filter.as_deref()).unwrap();
assert_eq!(
rendered,
vec![Language::Jni],
"sanity check: `--lang jni` must resolve to exactly [Jni], the path this test exercises"
);
rendered
}
fn assert_no_lang_pages_rendered(files: &[GeneratedFile]) {
assert!(
!files.iter().any(|f| f.path.to_str().unwrap().starts_with("out/api-")),
"no per-language page should render for `--lang c` alone"
);
}
#[test]
fn test_shared_pages_use_configured_union_for_the_lang_c_cli_path() {
let api = api_with_enum(pipeline_mode_enum(&[
PipelineVariantSpec {
name: "Turbo",
doc: "Multi-threaded accelerated mode.",
cfg_feature: Some("acceleration"),
is_default: false,
},
PipelineVariantSpec {
name: "NeverShipped",
doc: "Not enabled by any configured language.",
cfg_feature: Some("never-enabled"),
is_default: false,
},
]));
let config = config_from_toml(
r#"
[workspace]
languages = ["python", "wasm", "c"]
[[crates]]
name = "mylib"
sources = ["src/lib.rs"]
[crates.wasm]
features = ["acceleration"]
"#,
);
let rendered = resolve_lang_c(&config);
let files = generate_docs(&api, &config, &rendered, "out").unwrap();
assert_no_lang_pages_rendered(&files);
let types_file = shared_page_content(&files, "types");
assert!(
types_file.contains("`Turbo`"),
"`--lang c` must still describe the full configured surface (wasm enables this variant); \
got:\n{types_file}"
);
assert!(
!types_file.contains("NeverShipped"),
"`--lang c` must not fall back to the unfiltered surface just because no per-language \
page rendered this invocation -- the canonical union must come from config.languages, \
which is non-empty (python, wasm) here; got:\n{types_file}"
);
}
#[test]
fn test_shared_pages_use_configured_union_for_the_lang_jni_cli_path() {
let api = api_with_enum(pipeline_mode_enum(&[
PipelineVariantSpec {
name: "Turbo",
doc: "Multi-threaded accelerated mode.",
cfg_feature: Some("acceleration"),
is_default: false,
},
PipelineVariantSpec {
name: "NeverShipped",
doc: "Not enabled by any configured language.",
cfg_feature: Some("never-enabled"),
is_default: false,
},
]));
let config = config_from_toml(
r#"
[workspace]
languages = ["python", "wasm", "jni", "kotlin_android"]
[[crates]]
name = "mylib"
sources = ["src/lib.rs"]
[crates.wasm]
features = ["acceleration"]
"#,
);
let rendered = resolve_lang_jni(&config);
let files = generate_docs(&api, &config, &rendered, "out").unwrap();
assert_no_lang_pages_rendered(&files);
let types_file = shared_page_content(&files, "types");
assert!(
types_file.contains("`Turbo`"),
"`--lang jni` must still describe the full configured surface (wasm enables this \
variant); got:\n{types_file}"
);
assert!(
!types_file.contains("NeverShipped"),
"`--lang jni` must not fall back to the unfiltered surface just because no per-language \
page rendered this invocation -- the canonical union must come from config.languages, \
which is non-empty (python, wasm) here; got:\n{types_file}"
);
}