]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/nul-characters.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / nul-characters.rs
1 // Copyright 2013 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 pub fn main()
13 {
14 let all_nuls1 = "\0\x00\u{0}\u{0}";
15 let all_nuls2 = "\u{0}\u{0}\x00\0";
16 let all_nuls3 = "\u{0}\u{0}\x00\0";
17 let all_nuls4 = "\x00\u{0}\0\u{0}";
18
19 // sizes for two should suffice
20 assert_eq!(all_nuls1.len(), 4);
21 assert_eq!(all_nuls2.len(), 4);
22
23 // string equality should pass between the strings
24 assert_eq!(all_nuls1, all_nuls2);
25 assert_eq!(all_nuls2, all_nuls3);
26 assert_eq!(all_nuls3, all_nuls4);
27
28 // all extracted characters in all_nuls are equivalent to each other
29 for c1 in all_nuls1.chars()
30 {
31 for c2 in all_nuls1.chars()
32 {
33 assert_eq!(c1,c2);
34 }
35 }
36
37 // testing equality between explicit character literals
38 assert_eq!('\0', '\x00');
39 assert_eq!('\u{0}', '\x00');
40 assert_eq!('\u{0}', '\u{0}');
41
42 // NUL characters should make a difference
43 assert!("Hello World" != "Hello \0World");
44 assert!("Hello World" != "Hello World\0");
45 }