std: add test for str::as_c_str
This commit is contained in:
parent
7af56bb921
commit
cf75330807
3 changed files with 23 additions and 2 deletions
|
|
@ -380,7 +380,7 @@ pub fn link_exe(_src: &Path, _dest: &Path) -> bool {
|
|||
#[cfg(target_os = "freebsd")]
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn link_exe(src: &Path, dest: &Path) -> bool {
|
||||
use std::{libc, str};
|
||||
use std::libc;
|
||||
unsafe {
|
||||
do src.to_str().as_c_str |src_buf| {
|
||||
do dest.to_str().as_c_str |dest_buf| {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ use option::{Some, None};
|
|||
use os;
|
||||
use prelude::*;
|
||||
use ptr;
|
||||
use str;
|
||||
use task;
|
||||
use vec::ImmutableVector;
|
||||
|
||||
|
|
|
|||
|
|
@ -3116,6 +3116,28 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_as_c_str() {
|
||||
let a = ~"";
|
||||
do a.as_c_str |buf| {
|
||||
unsafe {
|
||||
assert_eq!(*ptr::offset(buf, 0), 0);
|
||||
}
|
||||
}
|
||||
|
||||
let a = ~"hello";
|
||||
do a.as_c_str |buf| {
|
||||
unsafe {
|
||||
assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char);
|
||||
assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char);
|
||||
assert_eq!(*ptr::offset(buf, 2), 'l' as libc::c_char);
|
||||
assert_eq!(*ptr::offset(buf, 3), 'l' as libc::c_char);
|
||||
assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char);
|
||||
assert_eq!(*ptr::offset(buf, 5), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_subslice_offset() {
|
||||
let a = "kernelsprite";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue