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:
parent
de8f417fc2
commit
e55c3a707f
1 changed files with 9 additions and 3 deletions
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue