PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/jruderman/rust
Rust | 48 lines | 41 code | 7 blank | 0 comment | 10 complexity | 6d1b0e1f175e7fb9a355cb47e1bd2516 MD5 | raw file
 1fn main() {
 2    let yen: char = '¥'; // 0xa5
 3    let c_cedilla: char = 'ç'; // 0xe7
 4    let thorn: char = 'þ'; // 0xfe
 5    let y_diaeresis: char = 'ÿ'; // 0xff
 6    let pi: char = 'Π'; // 0x3a0
 7
 8    assert (yen as int == 0xa5);
 9    assert (c_cedilla as int == 0xe7);
10    assert (thorn as int == 0xfe);
11    assert (y_diaeresis as int == 0xff);
12    assert (pi as int == 0x3a0);
13
14    assert (pi as int == '\u03a0' as int);
15    assert ('\x0a' as int == '\n' as int);
16
17    let bhutan: ~str = ~"འབྲུག་ཡུལ།";
18    let japan: ~str = ~"日本";
19    let uzbekistan: ~str = ~"Ўзбекистон";
20    let austria: ~str = ~"Österreich";
21
22    let bhutan_e: ~str =
23        ~"\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d";
24    let japan_e: ~str = ~"\u65e5\u672c";
25    let uzbekistan_e: ~str =
26        ~"\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d";
27    let austria_e: ~str = ~"\u00d6sterreich";
28
29    let oo: char = 'Ö';
30    assert (oo as int == 0xd6);
31
32    fn check_str_eq(a: ~str, b: ~str) {
33        let mut i: int = 0;
34        for str::each(a) |ab| {
35            log(debug, i);
36            log(debug, ab);
37            let bb: u8 = b[i];
38            log(debug, bb);
39            assert (ab == bb);
40            i += 1;
41        }
42    }
43
44    check_str_eq(bhutan, bhutan_e);
45    check_str_eq(japan, japan_e);
46    check_str_eq(uzbekistan, uzbekistan_e);
47    check_str_eq(austria, austria_e);
48}