2011-03-24 06:11:32 -05:00
|
|
|
|
use std;
|
2011-12-13 18:25:51 -06:00
|
|
|
|
import str;
|
|
|
|
|
import vec;
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
|
|
|
|
fn main() {
|
2011-07-27 07:19:39 -05:00
|
|
|
|
// Chars of 1, 2, 3, and 4 bytes
|
2011-08-19 17:16:48 -05:00
|
|
|
|
let chs: [char] = ['e', 'é', '€', 0x10000 as char];
|
2011-09-02 17:34:58 -05:00
|
|
|
|
let s: str = str::from_chars(chs);
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2012-02-12 02:14:05 -06:00
|
|
|
|
assert (str::len_bytes(s) == 10u);
|
|
|
|
|
assert (str::len(s) == 4u);
|
2012-01-30 22:44:48 -06:00
|
|
|
|
assert (vec::len::<char>(str::chars(s)) == 4u);
|
|
|
|
|
assert (str::eq(str::from_chars(str::chars(s)), s));
|
2011-09-01 19:27:58 -05:00
|
|
|
|
assert (str::char_at(s, 0u) == 'e');
|
|
|
|
|
assert (str::char_at(s, 1u) == 'é');
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2011-09-01 19:27:58 -05:00
|
|
|
|
assert (str::is_utf8(str::bytes(s)));
|
|
|
|
|
assert (!str::is_utf8([0x80_u8]));
|
|
|
|
|
assert (!str::is_utf8([0xc0_u8]));
|
|
|
|
|
assert (!str::is_utf8([0xc0_u8, 0x10_u8]));
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
|
let stack = "a×c€";
|
2011-09-01 19:27:58 -05:00
|
|
|
|
assert (str::pop_char(stack) == '€');
|
|
|
|
|
assert (str::pop_char(stack) == 'c');
|
|
|
|
|
str::push_char(stack, 'u');
|
2011-09-02 17:34:58 -05:00
|
|
|
|
assert (str::eq(stack, "a×u"));
|
2011-09-01 19:27:58 -05:00
|
|
|
|
assert (str::shift_char(stack) == 'a');
|
|
|
|
|
assert (str::shift_char(stack) == '×');
|
|
|
|
|
str::unshift_char(stack, 'ß');
|
2011-09-02 17:34:58 -05:00
|
|
|
|
assert (str::eq(stack, "ßu"));
|
2011-08-10 11:27:22 -05:00
|
|
|
|
}
|