about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-06-30 08:29:38 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-08-04 13:32:41 -0700
commitd5110854f76eac307e7a1729f3003e09d0277b60 (patch)
tree4267e56ae5f2c328e60d824de42d0be5ae7fbc5d /src/libstd
parentcd94e9121b082370a5b85d6ba431c04b79db7e10 (diff)
downloadrust-d5110854f76eac307e7a1729f3003e09d0277b60.tar.gz
rust-d5110854f76eac307e7a1729f3003e09d0277b60.zip
std: add test for str::as_c_str
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/str.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 2a24351fff4..e520c4d2476 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -3032,6 +3032,29 @@ mod tests {
         assert_eq!(s.to_c_str(), v);
     }
 
+    #[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";
         let b = a.slice(7, a.len());