]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/utf8.rs
auto merge of #20154 : P1start/rust/qualified-assoc-type-generics, r=nikomatsakis
[rust.git] / src / test / run-pass / utf8.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 //
11 // ignore-lexer-test FIXME #15679
12 // no-pretty-expanded FIXME #15189
13
14 pub fn main() {
15     let yen: char = '¥'; // 0xa5
16     let c_cedilla: char = 'ç'; // 0xe7
17     let thorn: char = 'þ'; // 0xfe
18     let y_diaeresis: char = 'ÿ'; // 0xff
19     let pi: char = 'Π'; // 0x3a0
20
21     assert_eq!(yen as int, 0xa5);
22     assert_eq!(c_cedilla as int, 0xe7);
23     assert_eq!(thorn as int, 0xfe);
24     assert_eq!(y_diaeresis as int, 0xff);
25     assert_eq!(pi as int, 0x3a0);
26
27     assert_eq!(pi as int, '\u03a0' as int);
28     assert_eq!('\x0a' as int, '\n' as int);
29
30     let bhutan: String = "འབྲུག་ཡུལ།".to_string();
31     let japan: String = "日本".to_string();
32     let uzbekistan: String = "Ўзбекистон".to_string();
33     let austria: String = "Österreich".to_string();
34
35     let bhutan_e: String =
36         "\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d".to_string();
37     let japan_e: String = "\u65e5\u672c".to_string();
38     let uzbekistan_e: String =
39         "\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d".to_string();
40     let austria_e: String = "\u00d6sterreich".to_string();
41
42     let oo: char = 'Ö';
43     assert_eq!(oo as int, 0xd6);
44
45     fn check_str_eq(a: String, b: String) {
46         let mut i: int = 0;
47         for ab in a.as_slice().bytes() {
48             println!("{}", i);
49             println!("{}", ab);
50             let bb: u8 = b.as_bytes()[i as uint];
51             println!("{}", bb);
52             assert_eq!(ab, bb);
53             i += 1;
54         }
55     }
56
57     check_str_eq(bhutan, bhutan_e);
58     check_str_eq(japan, japan_e);
59     check_str_eq(uzbekistan, uzbekistan_e);
60     check_str_eq(austria, austria_e);
61 }