use super::*;
#[test]
fn php_standalone_function_never_wraps_body_in_cfg() {
let backend = PhpBackend;
let api = ApiSurface {
crate_name: "test-lib".to_string(),
version: "0.1.0".to_string(),
types: vec![],
functions: vec![FunctionDef {
name: "count_tokens".to_string(),
rust_path: "test_lib::count_tokens".to_string(),
params: vec![ParamDef {
name: "text".to_string(),
ty: TypeRef::String,
..ParamDef::default()
}],
return_type: TypeRef::Primitive(PrimitiveType::U32),
cfg: Some(r#"feature = "tokenizer""#.to_string()),
..FunctionDef::default()
}],
enums: vec![],
errors: vec![],
excluded_type_paths: ::std::collections::HashMap::new(),
excluded_trait_names: ::std::collections::HashSet::new(),
services: vec![],
handler_contracts: vec![],
unsupported_public_items: Vec::new(),
};
let files = backend.generate_bindings(&api, &make_config()).unwrap();
let lib = files
.iter()
.find(|f| f.path.to_string_lossy().ends_with("lib.rs"))
.expect("lib.rs generated");
assert!(
lib.content.contains("fn count_tokens"),
"facade method must always be emitted (ext-php-rs's #[php_impl] can't tolerate a\
cfg'd-out method), got:\n{}",
lib.content
);
assert!(
!lib.content.contains("#[cfg("),
"facade method must never be cfg-gated, got:\n{}",
lib.content
);
assert!(
!lib.content.contains("not("),
"must never reintroduce a self-cancelling any(X, not(X)) predicate, got:\n{}",
lib.content
);
}