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