blob: 0e7a910e7e79cfdeb7be3d06b82f09b4ccf67d62 [file] [log] [blame]
David Tolnay0d47a532020-07-30 19:39:04 -07001use crate::gen::{generate, Opt};
2
3const CPP_EXAMPLE: &'static 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 opts = Opt {
15 include: Vec::new(),
16 cxx_impl_annotations: None,
17 };
18 let output = generate(CPP_EXAMPLE, opts, false).unwrap();
19 let output = std::str::from_utf8(&output).unwrap();
20 // To avoid continual breakage we won't test every byte.
21 // Let's look for the major features.
22 assert!(output.contains("void cxxbridge03$do_cpp_thing(::rust::Str::Repr foo)"));
23}
24
25#[test]
26fn test_annotation() {
27 let opts = Opt {
28 include: Vec::new(),
29 cxx_impl_annotations: Some("ANNOTATION".to_string()),
30 };
31 let output = generate(CPP_EXAMPLE, opts, false).unwrap();
32 let output = std::str::from_utf8(&output).unwrap();
33 assert!(output.contains("ANNOTATION void cxxbridge03$do_cpp_thing(::rust::Str::Repr foo)"));
34}