Skip to content

Commit

Permalink
add test cases for u32, bool, String
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Jul 3, 2023
1 parent 8fad54e commit 573bd75
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tests/ui/read_line_without_trim.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ fn main() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.trim_end().parse::<i32>().unwrap();

let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.trim_end().parse::<u32>().unwrap();

let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.trim_end().parse::<bool>().unwrap();

let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
// this is actually ok, so don't lint here
let _x = input.parse::<String>().unwrap();
}
13 changes: 13 additions & 0 deletions tests/ui/read_line_without_trim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ fn main() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.parse::<i32>().unwrap();

let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.parse::<u32>().unwrap();

let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.parse::<bool>().unwrap();

let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
// this is actually ok, so don't lint here
let _x = input.parse::<String>().unwrap();
}
30 changes: 29 additions & 1 deletion tests/ui/read_line_without_trim.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,33 @@ note: call to `.read_line()` here, which leaves a trailing newline character in
LL | std::io::stdin().read_line(&mut input).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
error: calling `.parse()` without trimming the trailing newline character
--> $DIR/read_line_without_trim.rs:22:20
|
LL | let _x = input.parse::<u32>().unwrap();
| ----- ^^^^^^^^^^^^^^
| |
| help: try: `input.trim_end()`
|
note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail
--> $DIR/read_line_without_trim.rs:21:5
|
LL | std::io::stdin().read_line(&mut input).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: calling `.parse()` without trimming the trailing newline character
--> $DIR/read_line_without_trim.rs:26:20
|
LL | let _x = input.parse::<bool>().unwrap();
| ----- ^^^^^^^^^^^^^^^
| |
| help: try: `input.trim_end()`
|
note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail
--> $DIR/read_line_without_trim.rs:25:5
|
LL | std::io::stdin().read_line(&mut input).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

0 comments on commit 573bd75

Please sign in to comment.