use super::*;
#[test]
fn binding_excluded_function_drops_the_non_rust_cell_but_keeps_rust() {
let fixture = documented_fixture();
let snippet_config = SnippetConfig {
output: "docs/snippets".into(),
..SnippetConfig::default()
};
let mut e2e = E2eConfig::default();
e2e.call.function = "excluded_core_fn".into();
let functions = vec![crate::core::ir::FunctionDef {
name: "excluded_core_fn".into(),
binding_excluded: true,
..crate::core::ir::FunctionDef::default()
}];
let crate_config = ResolvedCrateConfig::default();
let context = SnippetRenderContext {
e2e: &e2e,
crate_config: &crate_config,
type_defs: &[],
enums: &[],
functions: &functions,
errors: &[],
};
let report = generate_snippet_report_with_extensions(
&[fixture],
&["python".into(), "rust".into()],
&snippet_config,
&context,
&[],
)
.expect("a binding_excluded function must not abort the run");
let python_key = SnippetCoverageKey {
fixture_id: "extension_owned".into(),
language: "python".into(),
};
let rust_key = SnippetCoverageKey {
fixture_id: "extension_owned".into(),
language: "rust".into(),
};
assert_eq!(
report.coverage.expected,
vec![rust_key.clone()],
"a `binding_excluded` function must drop the python cell from `expected` while the \
rust carve-out keeps the rust cell: {:?}",
report.coverage.expected
);
assert!(
!report.coverage.expected.contains(&python_key),
"a `binding_excluded` function must not be expected for python: {:?}",
report.coverage.expected
);
assert!(
report.coverage.missing.is_empty(),
"a `binding_excluded` cell is not a coverage gap -- it must never have been expected \
in the first place, so it must not appear in `missing` either: {:?}",
report.coverage.missing
);
assert!(
report.coverage.generated.contains(&rust_key),
"the rust carve-out cell must still render: {:?}",
report.coverage.generated
);
}
#[test]
fn non_excluded_function_still_enters_expected_and_generated() {
let fixture = documented_fixture();
let snippet_config = SnippetConfig {
output: "docs/snippets".into(),
..SnippetConfig::default()
};
let mut e2e = E2eConfig::default();
e2e.call.function = "ordinary_core_fn".into();
let functions = vec![crate::core::ir::FunctionDef {
name: "ordinary_core_fn".into(),
binding_excluded: false,
..crate::core::ir::FunctionDef::default()
}];
let crate_config = ResolvedCrateConfig::default();
let context = SnippetRenderContext {
e2e: &e2e,
crate_config: &crate_config,
type_defs: &[],
enums: &[],
functions: &functions,
errors: &[],
};
let report =
generate_snippet_report_with_extensions(&[fixture], &["python".into()], &snippet_config, &context, &[])
.expect("an ordinary function must not abort the run");
let python_key = SnippetCoverageKey {
fixture_id: "extension_owned".into(),
language: "python".into(),
};
assert_eq!(
report.coverage.expected,
vec![python_key.clone()],
"a normal function must still be expected: {:?}",
report.coverage.expected
);
assert_eq!(
report.coverage.generated,
vec![python_key],
"a normal function must still generate: {:?}",
report.coverage.generated
);
}