2011-03-24 06:11:32 -05:00
|
|
|
|
use std;
|
2011-08-31 17:23:34 -05:00
|
|
|
|
import std::istr;
|
2011-08-15 18:38:23 -05:00
|
|
|
|
import std::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-08-31 17:23:34 -05:00
|
|
|
|
let s: istr = istr::from_chars(chs);
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2011-08-31 17:23:34 -05:00
|
|
|
|
assert (istr::byte_len(s) == 10u);
|
|
|
|
|
assert (istr::char_len(s) == 4u);
|
|
|
|
|
assert (vec::len::<char>(istr::to_chars(s)) == 4u);
|
|
|
|
|
assert (istr::eq(istr::from_chars(istr::to_chars(s)), s));
|
|
|
|
|
assert (istr::char_at(s, 0u) == 'e');
|
|
|
|
|
assert (istr::char_at(s, 1u) == 'é');
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2011-08-31 17:23:34 -05:00
|
|
|
|
assert (istr::is_utf8(istr::bytes(s)));
|
|
|
|
|
assert (!istr::is_utf8([0x80_u8]));
|
|
|
|
|
assert (!istr::is_utf8([0xc0_u8]));
|
|
|
|
|
assert (!istr::is_utf8([0xc0_u8, 0x10_u8]));
|
2011-03-24 06:11:32 -05:00
|
|
|
|
|
2011-08-31 17:23:34 -05:00
|
|
|
|
let stack = ~"a×c€";
|
|
|
|
|
assert (istr::pop_char(stack) == '€');
|
|
|
|
|
assert (istr::pop_char(stack) == 'c');
|
|
|
|
|
istr::push_char(stack, 'u');
|
|
|
|
|
assert (istr::eq(stack, ~"a×u"));
|
|
|
|
|
assert (istr::shift_char(stack) == 'a');
|
|
|
|
|
assert (istr::shift_char(stack) == '×');
|
|
|
|
|
istr::unshift_char(stack, 'ß');
|
|
|
|
|
assert (istr::eq(stack, ~"ßu"));
|
2011-08-10 11:27:22 -05:00
|
|
|
|
}
|