about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-07-22 21:42:51 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-07-23 16:56:22 -0700
commitcf75330807ad908a428e9c162a388e367fb07781 (patch)
tree2b7f255054bd1ffca57fc5e7dc55eca73288f3da /src/libstd
parent7af56bb92199eabcfee52c43739761b18872a2c1 (diff)
downloadrust-cf75330807ad908a428e9c162a388e367fb07781.tar.gz
rust-cf75330807ad908a428e9c162a388e367fb07781.zip
std: add test for str::as_c_str
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/run.rs1
-rw-r--r--src/libstd/str.rs22
2 files changed, 22 insertions, 1 deletions
diff --git a/src/libstd/run.rs b/src/libstd/run.rs
index d8fc68d6422..b6cc556af10 100644
--- a/src/libstd/run.rs
+++ b/src/libstd/run.rs
@@ -23,7 +23,6 @@ use option::{Some, None};
 use os;
 use prelude::*;
 use ptr;
-use str;
 use task;
 use vec::ImmutableVector;
 
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index ab3d362ba79..5bd084b8796 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -3117,6 +3117,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";
         let b = a.slice(7, a.len());