aboutsummaryrefslogtreecommitdiff
path: root/src/test/run-pass/lib-vec-str-conversions.rs
diff options
context:
space:
mode:
authorRoy Frostig <[email protected]>2010-08-11 16:06:45 -0700
committerRoy Frostig <[email protected]>2010-08-11 16:06:45 -0700
commitf307688bf44404b371b91b3b2a67048088695fe1 (patch)
treecfd89b43e614588ea7ee35eebd8f83eec3f5fedf /src/test/run-pass/lib-vec-str-conversions.rs
parentFix reverse-indexing bug in _vec.init_fn. (diff)
downloadrust-f307688bf44404b371b91b3b2a67048088695fe1.tar.xz
rust-f307688bf44404b371b91b3b2a67048088695fe1.zip
Add native vec[u8] to str converter. Put in workaround for leak in str to vec[u8] converter. Add testcase exercising both. Drive-by fix a potential array-out-of-bounds write on rust_str buffers.
Diffstat (limited to 'src/test/run-pass/lib-vec-str-conversions.rs')
-rw-r--r--src/test/run-pass/lib-vec-str-conversions.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/run-pass/lib-vec-str-conversions.rs b/src/test/run-pass/lib-vec-str-conversions.rs
new file mode 100644
index 00000000..1d6b61a1
--- /dev/null
+++ b/src/test/run-pass/lib-vec-str-conversions.rs
@@ -0,0 +1,41 @@
+// -*- rust -*-
+
+use std;
+import std._str;
+import std._vec;
+
+fn test_simple() {
+ let str s1 = "All mimsy were the borogoves";
+
+ /*
+ * FIXME from_bytes(vec[u8] v) has constraint is_utf(v), which is
+ * unimplemented and thereby just fails. This doesn't stop us from
+ * using from_bytes for now since the constraint system isn't fully
+ * working, but we should implement is_utf8 before that happens.
+ */
+
+ let vec[u8] v = _str.bytes(s1);
+ let str s2 = _str.from_bytes(v);
+
+ let uint i = 0u;
+ let uint n1 = _str.byte_len(s1);
+ let uint n2 = _vec.len[u8](v);
+
+ check (n1 == n2);
+
+ while (i < n1) {
+ let u8 a = s1.(i);
+ let u8 b = s2.(i);
+ log a;
+ log b;
+ check (a == b);
+ i += 1u;
+ }
+
+ log "refcnt is";
+ log _str.refcount(s1);
+}
+
+fn main() {
+ test_simple();
+}