Skip to content

Commit d511085

Browse files
committed
std: add test for str::as_c_str
1 parent cd94e91 commit d511085

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libstd/str.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,6 +3032,29 @@ mod tests {
30323032
assert_eq!(s.to_c_str(), v);
30333033
}
30343034
3035+
#[test]
3036+
fn test_as_c_str() {
3037+
let a = ~"";
3038+
do a.as_c_str |buf| {
3039+
unsafe {
3040+
assert_eq!(*ptr::offset(buf, 0), 0);
3041+
}
3042+
}
3043+
3044+
let a = ~"hello";
3045+
do a.as_c_str |buf| {
3046+
unsafe {
3047+
assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char);
3048+
assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char);
3049+
assert_eq!(*ptr::offset(buf, 2), 'l' as libc::c_char);
3050+
assert_eq!(*ptr::offset(buf, 3), 'l' as libc::c_char);
3051+
assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char);
3052+
assert_eq!(*ptr::offset(buf, 5), 0);
3053+
}
3054+
}
3055+
}
3056+
3057+
#[test]
30353058
fn test_subslice_offset() {
30363059
let a = "kernelsprite";
30373060
let b = a.slice(7, a.len());

0 commit comments

Comments
 (0)