PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/src/test/run-pass/utf8_chars.rs

http://github.com/jruderman/rust
Rust | 31 lines | 26 code | 4 blank | 1 comment | 12 complexity | 6a628a9850f5bdd6e44f4d6e5bc2502d MD5 | raw file
 1use std;
 2import str;
 3import vec;
 4
 5fn main() {
 6    // Chars of 1, 2, 3, and 4 bytes
 7    let chs: ~[char] = ~['e', 'é', '€', 0x10000 as char];
 8    let s: ~str = str::from_chars(chs);
 9
10    assert (str::len(s) == 10u);
11    assert (str::char_len(s) == 4u);
12    assert (vec::len(str::chars(s)) == 4u);
13    assert (str::from_chars(str::chars(s)) == s);
14    assert (str::char_at(s, 0u) == 'e');
15    assert (str::char_at(s, 1u) == 'é');
16
17    assert (str::is_utf8(str::bytes(s)));
18    assert (!str::is_utf8(~[0x80_u8]));
19    assert (!str::is_utf8(~[0xc0_u8]));
20    assert (!str::is_utf8(~[0xc0_u8, 0x10_u8]));
21
22    let mut stack = ~"a×c€";
23    assert (str::pop_char(stack) == '€');
24    assert (str::pop_char(stack) == 'c');
25    str::push_char(stack, 'u');
26    assert (stack == ~"a×u");
27    assert (str::shift_char(stack) == 'a');
28    assert (str::shift_char(stack) == '×');
29    str::unshift_char(stack, 'ß');
30    assert (stack == ~"ßu");
31}