cxx/tests/cxx_gen.rs

32 lines
1.0 KiB
Rust
Raw Normal View History

use cxx_gen::{generate_header_and_cc, Opt};
2020-08-29 23:50:14 -07:00
const CPP_EXAMPLE: &str = r#"
#[cxx::bridge]
mod ffi {
extern "C" {
pub fn do_cpp_thing(foo: &str);
}
}
2020-08-29 23:50:14 -07:00
"#;
#[test]
fn test_cpp() {
let opt = Opt::default();
let source = CPP_EXAMPLE.parse().unwrap();
let output = generate_header_and_cc(source, &opt).unwrap();
let output = std::str::from_utf8(&output.implementation).unwrap();
// To avoid continual breakage we won't test every byte.
// Let's look for the major features.
2020-09-01 23:00:38 -07:00
assert!(output.contains("void cxxbridge04$do_cpp_thing(::rust::Str::Repr foo)"));
}
#[test]
fn test_annotation() {
let mut opt = Opt::default();
opt.cxx_impl_annotations = Some("ANNOTATION".to_owned());
let source = CPP_EXAMPLE.parse().unwrap();
let output = generate_header_and_cc(source, &opt).unwrap();
let output = std::str::from_utf8(&output.implementation).unwrap();
2020-09-01 23:00:38 -07:00
assert!(output.contains("ANNOTATION void cxxbridge04$do_cpp_thing(::rust::Str::Repr foo)"));
}