]> git.lizzy.rs Git - rust.git/blob - tests/ui/write_with_newline.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / write_with_newline.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![allow(clippy::write_literal)]
11 #![warn(clippy::write_with_newline)]
12
13 use std::io::Write;
14
15 fn main() {
16     let mut v = Vec::new();
17
18     // These should fail
19     write!(&mut v, "Hello\n");
20     write!(&mut v, "Hello {}\n", "world");
21     write!(&mut v, "Hello {} {}\n", "world", "#2");
22     write!(&mut v, "{}\n", 1265);
23
24     // These should be fine
25     write!(&mut v, "");
26     write!(&mut v, "Hello");
27     writeln!(&mut v, "Hello");
28     writeln!(&mut v, "Hello\n");
29     writeln!(&mut v, "Hello {}\n", "world");
30     write!(&mut v, "Issue\n{}", 1265);
31     write!(&mut v, "{}", 1265);
32     write!(&mut v, "\n{}", 1275);
33     write!(&mut v, "\n\n");
34     write!(&mut v, "like eof\n\n");
35     write!(&mut v, "Hello {} {}\n\n", "world", "#2");
36     writeln!(&mut v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
37     writeln!(&mut v, "\nbla\n\n"); // #3126
38
39     // Escaping
40     write!(&mut v, "\\n"); // #3514
41     write!(&mut v, "\\\n");
42     write!(&mut v, "\\\\n");
43 }