aboutsummaryrefslogtreecommitdiff
path: root/src/test/run-pass/lib-vec-str-conversions.rs
blob: cd8b64a889e24b970f903ce95067ac399ac8deea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);

  assert (n1 == n2);

  while (i < n1) {
    let u8 a = s1.(i);
    let u8 b = s2.(i);
    log a;
    log b;
    assert (a == b);
    i += 1u;
  }

  log "refcnt is";
  log Str.refcount(s1);
}

fn main() {
  test_simple();
}