1 #![allow(clippy::field_reassign_with_default)] 2 3 use cxx_gen::{generate_header_and_cc, Opt}; 4 use std::str; 5 6 const BRIDGE0: &str = r#" 7 #[cxx::bridge] 8 mod ffi { 9 unsafe extern "C++" { 10 pub fn do_cpp_thing(foo: &str); 11 } 12 } 13 "#; 14 15 #[test] test_extern_c_function()16fn test_extern_c_function() { 17 let opt = Opt::default(); 18 let source = BRIDGE0.parse().unwrap(); 19 let generated = generate_header_and_cc(source, &opt).unwrap(); 20 let output = str::from_utf8(&generated.implementation).unwrap(); 21 // To avoid continual breakage we won't test every byte. 22 // Let's look for the major features. 23 assert!(output.contains("void cxxbridge1$do_cpp_thing(::rust::Str foo)")); 24 } 25 26 #[test] test_impl_annotation()27fn test_impl_annotation() { 28 let mut opt = Opt::default(); 29 opt.cxx_impl_annotations = Some("ANNOTATION".to_owned()); 30 let source = BRIDGE0.parse().unwrap(); 31 let generated = generate_header_and_cc(source, &opt).unwrap(); 32 let output = str::from_utf8(&generated.implementation).unwrap(); 33 assert!(output.contains("ANNOTATION void cxxbridge1$do_cpp_thing(::rust::Str foo)")); 34 } 35