const PYO3_MODULE: &str = include_str!("../src/pyo3_module.rs");
fn binds_render_table(src: &str) -> bool {
let Some(at) = src.find("#[pyo3(name = \"render_table\")]") else {
return false;
};
src[at..]
.lines()
.skip(1)
.map(str::trim_start)
.find(|l| !l.is_empty() && !l.starts_with("//"))
.is_some_and(|l| l.starts_with("fn table("))
}
#[test]
fn the_python_scorecard_still_exposes_render_table() {
assert!(
binds_render_table(PYO3_MODULE),
"PyScorecard must expose `render_table` to Python. \
newt-agent-py/tests/test_eval.py::test_scorecard_renders_table \
calls it, and the Rust method is named `table` so the sprawl \
ratchet stops counting a binding as a table implementation."
);
}
#[test]
fn the_guard_can_fail() {
assert!(binds_render_table(
"#[pyo3(name = \"render_table\")]\n fn table(&self) -> String {"
));
assert!(binds_render_table(
"#[pyo3(name = \"render_table\")]\n\n fn table(&self) -> String {"
));
assert!(binds_render_table(
"#[pyo3(name = \"render_table\")]\n /// doc\n fn table(&self) {"
));
assert!(!binds_render_table(" fn table(&self) -> String {"));
assert!(!binds_render_table(
"#[pyo3(name = \"render_table\")]\n fn cases(&self) -> Vec<String> {"
));
assert!(!binds_render_table(""));
}