]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/byte-literals.rs
librustc: Remove the fallback to `int` from typechecking.
[rust.git] / src / test / run-pass / byte-literals.rs
1 // Copyright 2014 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
12 static FOO: u8 = b'\xF0';
13 static BAR: &'static [u8] = b"a\xF0\t";
14 static BAZ: &'static [u8] = br"a\n";
15
16 pub fn main() {
17     assert_eq!(b'a', 97u8);
18     assert_eq!(b'\n', 10u8);
19     assert_eq!(b'\r', 13u8);
20     assert_eq!(b'\t', 9u8);
21     assert_eq!(b'\\', 92u8);
22     assert_eq!(b'\'', 39u8);
23     assert_eq!(b'\"', 34u8);
24     assert_eq!(b'\0', 0u8);
25     assert_eq!(b'\xF0', 240u8);
26     assert_eq!(FOO, 240u8);
27
28     match 42 {
29         b'*' => {},
30         _ => fail!()
31     }
32
33     match 100 {
34         b'a' .. b'z' => {},
35         _ => fail!()
36     }
37
38     assert_eq!(b"a\n\r\t\\\'\"\0\xF0",
39                &[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8]);
40     assert_eq!(b"a\
41                  b", &[97u8, 98u8]);
42     assert_eq!(BAR, &[97u8, 240u8, 9u8]);
43
44     match &[97u8, 10u8] {
45         b"a\n" => {},
46         _ => fail!(),
47     }
48
49     assert_eq!(BAZ, &[97u8, 92u8, 110u8]);
50     assert_eq!(br"a\n", &[97u8, 92u8, 110u8]);
51     assert_eq!(br"a\n", b"a\\n");
52     assert_eq!(br###"a"##b"###, &[97u8, 34u8, 35u8, 35u8, 98u8]);
53     assert_eq!(br###"a"##b"###, b"a\"##b");
54 }