1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-10-30 11:54:01 -04:00

Rust: test return values

This commit is contained in:
Alex Kotov 2022-01-25 04:04:07 +05:00
parent de8f417fc2
commit e55c3a707f
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -29,25 +29,31 @@ mod tests {
#[test]
fn utoa() {
let mut buffer: [i8; 1000] = [0; 1000];
unsafe { kernaux_utoa(0x123, buffer.as_mut_ptr(), 'x' as c_int) };
let end: *mut c_char =
unsafe { kernaux_utoa(0x123, buffer.as_mut_ptr(), 'x' as c_int) };
let result =
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
assert_eq!(result, "123");
assert_eq!(end, unsafe { buffer.as_mut_ptr().offset(3) });
}
#[test]
fn itoa() {
let mut buffer: [i8; 1000] = [0; 1000];
unsafe { kernaux_itoa(0x123, buffer.as_mut_ptr(), 'x' as c_int) };
let end: *mut c_char =
unsafe { kernaux_itoa(0x123, buffer.as_mut_ptr(), 'x' as c_int) };
let result =
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
assert_eq!(result, "123");
assert_eq!(end, unsafe { buffer.as_mut_ptr().offset(3) });
let mut buffer: [i8; 1000] = [0; 1000];
unsafe { kernaux_itoa(-0x123, buffer.as_mut_ptr(), 'x' as c_int) };
let end: *mut c_char =
unsafe { kernaux_itoa(-0x123, buffer.as_mut_ptr(), 'x' as c_int) };
let result =
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
assert_eq!(result, "-123");
assert_eq!(end, unsafe { buffer.as_mut_ptr().offset(4) });
}
#[test]