alpino_tokenizer_sys/
lib.rs

1use std::os::raw::c_int;
2
3use widestring::WideChar;
4
5extern "C" {
6    pub fn new_t_accepts(input: *const WideChar, out: *mut *mut WideChar, max: *mut usize)
7        -> c_int;
8}
9
10#[cfg(test)]
11mod tests {
12    use core::ffi::c_void;
13    use std::mem;
14
15    use libc::{free, malloc};
16    use widestring::{WideCString, WideChar};
17
18    use super::new_t_accepts;
19
20    #[test]
21    fn test_new_t_accepts() {
22        let input = WideCString::from_str("Dit is een test. En nog een zin.").unwrap();
23        let mut output_len = input.len() + 1;
24        let mut output =
25            unsafe { malloc(output_len * mem::size_of::<WideChar>()) } as *mut WideChar;
26        assert_eq!(
27            unsafe { new_t_accepts(input.as_ptr(), &mut output, &mut output_len) },
28            1
29        );
30
31        let output_str = unsafe { WideCString::from_ptr_with_nul(output, output_len) }.unwrap();
32        assert_eq!(
33            output_str.to_string_lossy(),
34            "Dit is een test .\nEn nog een zin ."
35        );
36        unsafe { free(output as *mut c_void) };
37    }
38}