]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/byte-literals.rs
Auto merge of #23934 - lfairy:write-no-deref, r=alexcrichton
[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 // ignore-lexer-test FIXME #15883
12
13
14 static FOO: u8 = b'\xF0';
15 static BAR: &'static [u8] = b"a\xF0\t";
16 static BAR_FIXED: &'static [u8; 3] = b"a\xF0\t";
17 static BAZ: &'static [u8] = br"a\n";
18
19 pub fn main() {
20     let bar: &'static [u8] = b"a\xF0\t";
21     let bar_fixed: &'static [u8; 3] = b"a\xF0\t";
22
23     assert_eq!(b'a', 97u8);
24     assert_eq!(b'\n', 10u8);
25     assert_eq!(b'\r', 13u8);
26     assert_eq!(b'\t', 9u8);
27     assert_eq!(b'\\', 92u8);
28     assert_eq!(b'\'', 39u8);
29     assert_eq!(b'\"', 34u8);
30     assert_eq!(b'\0', 0u8);
31     assert_eq!(b'\xF0', 240u8);
32     assert_eq!(FOO, 240u8);
33
34     match 42 {
35         b'*' => {},
36         _ => panic!()
37     }
38
39     match 100 {
40         b'a' ... b'z' => {},
41         _ => panic!()
42     }
43
44     let expected: &[_] = &[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8];
45     assert_eq!(b"a\n\r\t\\\'\"\0\xF0", expected);
46     let expected: &[_] = &[97u8, 98u8];
47     assert_eq!(b"a\
48                  b", expected);
49     let expected: &[_] = &[97u8, 240u8, 9u8];
50     assert_eq!(BAR, expected);
51     assert_eq!(BAR_FIXED, expected);
52     assert_eq!(bar, expected);
53     assert_eq!(bar_fixed, expected);
54
55     let val = &[97u8, 10u8];
56     match val {
57         b"a\n" => {},
58         _ => panic!(),
59     }
60
61     let buf = vec!(97u8, 98, 99, 100);
62     assert_eq!(match &buf[0..3] {
63          b"def" => 1,
64          b"abc" => 2,
65          _ => 3
66     }, 2);
67
68     let expected: &[_] = &[97u8, 92u8, 110u8];
69     assert_eq!(BAZ, expected);
70     let expected: &[_] = &[97u8, 92u8, 110u8];
71     assert_eq!(br"a\n", expected);
72     assert_eq!(br"a\n", b"a\\n");
73     let expected: &[_] = &[97u8, 34u8, 35u8, 35u8, 98u8];
74     assert_eq!(br###"a"##b"###, expected);
75     assert_eq!(br###"a"##b"###, b"a\"##b");
76 }