| David Tolnay | 0d47a53 | 2020-07-30 19:39:04 -0700 | [diff] [blame^] | 1 | use crate::gen::{generate, Opt}; |
| 2 | |
| 3 | const 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] |
| 13 | fn 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] |
| 26 | fn 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 | } |