blob: b5ff10618215f5d8f613c618b4a0d4068f3bf3cd [file] [log] [blame]
David Tolnay821402b2020-10-04 19:48:01 -07001use cxx_gen::{generate_header_and_cc, Opt};
2
3const CPP_EXAMPLE: &str = r#"
4 #[cxx::bridge]
5 mod ffi {
6 extern "C" {
7 pub fn do_cpp_thing(foo: &str);
8 }
9 }
10"#;
11
12#[test]
13fn test_cpp() {
14 let opt = Opt::default();
15 let source = CPP_EXAMPLE.parse().unwrap();
16 let output = generate_header_and_cc(source, &opt).unwrap();
17 let output = std::str::from_utf8(&output.implementation).unwrap();
18 // To avoid continual breakage we won't test every byte.
19 // Let's look for the major features.
20 assert!(output.contains("void cxxbridge04$do_cpp_thing(::rust::Str::Repr foo)"));
21}
22
23#[test]
24fn test_annotation() {
25 let mut opt = Opt::default();
26 opt.cxx_impl_annotations = Some("ANNOTATION".to_owned());
27 let source = CPP_EXAMPLE.parse().unwrap();
28 let output = generate_header_and_cc(source, &opt).unwrap();
29 let output = std::str::from_utf8(&output.implementation).unwrap();
30 assert!(output.contains("ANNOTATION void cxxbridge04$do_cpp_thing(::rust::Str::Repr foo)"));
31}