mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Moved the tests for lint search_is_some
to new files
`search_is_some.rs` and `search_is_some_fixable.rs`
This commit is contained in:
parent
a1cf2d334d
commit
431fcbcc00
3 changed files with 74 additions and 63 deletions
|
@ -133,69 +133,6 @@ fn filter_next() {
|
|||
let _ = foo.filter().next();
|
||||
}
|
||||
|
||||
/// Checks implementation of `SEARCH_IS_SOME` lint.
|
||||
#[rustfmt::skip]
|
||||
fn search_is_some() {
|
||||
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
||||
let y = &&42;
|
||||
|
||||
// Check `find().is_some()`, single-line case.
|
||||
let _ = v.iter().find(|&x| *x < 0).is_some();
|
||||
let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
|
||||
let _ = (0..1).find(|x| *x == 0).is_some();
|
||||
let _ = v.iter().find(|x| **x == 0).is_some();
|
||||
|
||||
// Check `find().is_some()`, multi-line case.
|
||||
let _ = v.iter().find(|&x| {
|
||||
*x < 0
|
||||
}
|
||||
).is_some();
|
||||
|
||||
// Check `position().is_some()`, single-line case.
|
||||
let _ = v.iter().position(|&x| x < 0).is_some();
|
||||
|
||||
// Check `position().is_some()`, multi-line case.
|
||||
let _ = v.iter().position(|&x| {
|
||||
x < 0
|
||||
}
|
||||
).is_some();
|
||||
|
||||
// Check `rposition().is_some()`, single-line case.
|
||||
let _ = v.iter().rposition(|&x| x < 0).is_some();
|
||||
|
||||
// Check `rposition().is_some()`, multi-line case.
|
||||
let _ = v.iter().rposition(|&x| {
|
||||
x < 0
|
||||
}
|
||||
).is_some();
|
||||
|
||||
let s1 = String::from("hello world");
|
||||
let s2 = String::from("world");
|
||||
// Check caller `find()` is a &`static str case
|
||||
let _ = "hello world".find("world").is_some();
|
||||
let _ = "hello world".find(&s2).is_some();
|
||||
let _ = "hello world".find(&s2[2..]).is_some();
|
||||
// Check caller of `find()` is a String case
|
||||
let _ = s1.find("world").is_some();
|
||||
let _ = s1.find(&s2).is_some();
|
||||
let _ = s1.find(&s2[2..]).is_some();
|
||||
// Check caller of `find()` is a slice of String case
|
||||
let _ = s1[2..].find("world").is_some();
|
||||
let _ = s1[2..].find(&s2).is_some();
|
||||
let _ = s1[2..].find(&s2[2..]).is_some();
|
||||
|
||||
// Check that we don't lint if `find()` is called with
|
||||
// Pattern that is not a string
|
||||
let _ = s1.find(|c: char| c == 'o' || c == 'l').is_some();
|
||||
|
||||
// Check that we don't lint if the caller is not an `Iterator` or string
|
||||
let foo = IteratorFalsePositives { foo: 0 };
|
||||
let _ = foo.find().is_some();
|
||||
let _ = foo.position().is_some();
|
||||
let _ = foo.rposition().is_some();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
filter_next();
|
||||
search_is_some();
|
||||
}
|
||||
|
|
39
tests/ui/search_is_some.rs
Normal file
39
tests/ui/search_is_some.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
#[macro_use]
|
||||
extern crate option_helpers;
|
||||
use option_helpers::IteratorFalsePositives;
|
||||
|
||||
#[warn(clippy::search_is_some)]
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
||||
let y = &&42;
|
||||
|
||||
|
||||
// Check `find().is_some()`, multi-line case.
|
||||
let _ = v.iter().find(|&x| {
|
||||
*x < 0
|
||||
}
|
||||
).is_some();
|
||||
|
||||
// Check `position().is_some()`, multi-line case.
|
||||
let _ = v.iter().position(|&x| {
|
||||
x < 0
|
||||
}
|
||||
).is_some();
|
||||
|
||||
// Check `rposition().is_some()`, multi-line case.
|
||||
let _ = v.iter().rposition(|&x| {
|
||||
x < 0
|
||||
}
|
||||
).is_some();
|
||||
|
||||
// Check that we don't lint if the caller is not an `Iterator` or string
|
||||
let foo = IteratorFalsePositives { foo: 0 };
|
||||
let _ = foo.find().is_some();
|
||||
let _ = foo.position().is_some();
|
||||
let _ = foo.rposition().is_some();
|
||||
// check that we don't lint if `find()` is called with
|
||||
// `Pattern` that is not a string
|
||||
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some();
|
||||
}
|
||||
|
35
tests/ui/search_is_some_fixable.rs
Normal file
35
tests/ui/search_is_some_fixable.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::search_is_some)]
|
||||
|
||||
fn main() {
|
||||
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
||||
let y = &&42;
|
||||
|
||||
// Check `find().is_some()`, single-line case.
|
||||
let _ = v.iter().find(|&x| *x < 0).is_some();
|
||||
let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
|
||||
let _ = (0..1).find(|x| *x == 0).is_some();
|
||||
let _ = v.iter().find(|x| **x == 0).is_some();
|
||||
|
||||
// Check `position().is_some()`, single-line case.
|
||||
let _ = v.iter().position(|&x| x < 0).is_some();
|
||||
|
||||
// Check `rposition().is_some()`, single-line case.
|
||||
let _ = v.iter().rposition(|&x| x < 0).is_some();
|
||||
|
||||
let s1 = String::from("hello world");
|
||||
let s2 = String::from("world");
|
||||
// caller of `find()` is a `&`static str`
|
||||
let _ = "hello world".find("world").is_some();
|
||||
let _ = "hello world".find(&s2).is_some();
|
||||
let _ = "hello world".find(&s2[2..]).is_some();
|
||||
// caller of `find()` is a `String`
|
||||
let _ = s1.find("world").is_some();
|
||||
let _ = s1.find(&s2).is_some();
|
||||
let _ = s1.find(&s2[2..]).is_some();
|
||||
// caller of `find()` is slice of `String`
|
||||
let _ = s1[2..].find("world").is_some();
|
||||
let _ = s1[2..].find(&s2).is_some();
|
||||
let _ = s1[2..].find(&s2[2..]).is_some();
|
||||
}
|
Loading…
Reference in a new issue