]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | // | |
1a4d82fc JJ |
11 | |
12 | ||
13 | static FOO: u8 = b'\xF0'; | |
14 | static BAR: &'static [u8] = b"a\xF0\t"; | |
c34b1796 | 15 | static BAR_FIXED: &'static [u8; 3] = b"a\xF0\t"; |
1a4d82fc JJ |
16 | static BAZ: &'static [u8] = br"a\n"; |
17 | ||
18 | pub fn main() { | |
c34b1796 AL |
19 | let bar: &'static [u8] = b"a\xF0\t"; |
20 | let bar_fixed: &'static [u8; 3] = b"a\xF0\t"; | |
21 | ||
1a4d82fc JJ |
22 | assert_eq!(b'a', 97u8); |
23 | assert_eq!(b'\n', 10u8); | |
24 | assert_eq!(b'\r', 13u8); | |
25 | assert_eq!(b'\t', 9u8); | |
26 | assert_eq!(b'\\', 92u8); | |
27 | assert_eq!(b'\'', 39u8); | |
28 | assert_eq!(b'\"', 34u8); | |
29 | assert_eq!(b'\0', 0u8); | |
30 | assert_eq!(b'\xF0', 240u8); | |
31 | assert_eq!(FOO, 240u8); | |
32 | ||
33 | match 42 { | |
34 | b'*' => {}, | |
35 | _ => panic!() | |
36 | } | |
37 | ||
38 | match 100 { | |
39 | b'a' ... b'z' => {}, | |
40 | _ => panic!() | |
41 | } | |
42 | ||
43 | let expected: &[_] = &[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8]; | |
44 | assert_eq!(b"a\n\r\t\\\'\"\0\xF0", expected); | |
45 | let expected: &[_] = &[97u8, 98u8]; | |
46 | assert_eq!(b"a\ | |
47 | b", expected); | |
48 | let expected: &[_] = &[97u8, 240u8, 9u8]; | |
49 | assert_eq!(BAR, expected); | |
c34b1796 AL |
50 | assert_eq!(BAR_FIXED, expected); |
51 | assert_eq!(bar, expected); | |
52 | assert_eq!(bar_fixed, expected); | |
1a4d82fc | 53 | |
c34b1796 | 54 | let val = &[97u8, 10u8]; |
1a4d82fc JJ |
55 | match val { |
56 | b"a\n" => {}, | |
57 | _ => panic!(), | |
58 | } | |
59 | ||
c30ab7b3 | 60 | let buf = vec![97u8, 98, 99, 100]; |
85aaf69f | 61 | assert_eq!(match &buf[0..3] { |
c34b1796 AL |
62 | b"def" => 1, |
63 | b"abc" => 2, | |
64 | _ => 3 | |
1a4d82fc JJ |
65 | }, 2); |
66 | ||
67 | let expected: &[_] = &[97u8, 92u8, 110u8]; | |
68 | assert_eq!(BAZ, expected); | |
69 | let expected: &[_] = &[97u8, 92u8, 110u8]; | |
70 | assert_eq!(br"a\n", expected); | |
71 | assert_eq!(br"a\n", b"a\\n"); | |
72 | let expected: &[_] = &[97u8, 34u8, 35u8, 35u8, 98u8]; | |
73 | assert_eq!(br###"a"##b"###, expected); | |
74 | assert_eq!(br###"a"##b"###, b"a\"##b"); | |
75 | } |