Skip to content

Commit

Permalink
Auto merge of #8150 - flip1995:clippy_utils_test, r=xFrednet
Browse files Browse the repository at this point in the history
Test clippy_utils in CI

r? `@xFrednet` Since you did the last refactor of the `str_utils` functions in #7873

changelog: Make sure tests in `clippy_utils` are passing by testing it in CI
  • Loading branch information
bors committed Dec 20, 2021
2 parents 7905130 + eb47398 commit fea103d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ jobs:
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
working-directory: clippy_lints

- name: Test clippy_utils
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
working-directory: clippy_utils

- name: Test rustc_tools_util
run: cargo test --features deny-warnings
working-directory: rustc_tools_util
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ jobs:
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
working-directory: clippy_lints

- name: Test clippy_utils
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
working-directory: clippy_utils

- name: Test rustc_tools_util
run: cargo test --features deny-warnings
working-directory: rustc_tools_util
Expand Down
17 changes: 10 additions & 7 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
/// instead.
///
/// Examples:
/// ```ignore
/// ```
/// let abc = 1;
/// // ^ output
/// let def = abc;
/// dbg!(def)
/// dbg!(def);
/// // ^^^ input
///
/// // or...
/// let abc = 1;
/// let def = abc + 2;
/// // ^^^^^^^ output
/// dbg!(def)
/// dbg!(def);
/// // ^^^ input
/// ```
pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr<'b>) -> &'a Expr<'b> {
Expand Down Expand Up @@ -1136,7 +1136,7 @@ pub fn find_macro_calls(names: &[&str], body: &Body<'_>) -> Vec<Span> {

/// Extends the span to the beginning of the spans line, incl. whitespaces.
///
/// ```rust,ignore
/// ```rust
/// let x = ();
/// // ^^
/// // will be converted to
Expand Down Expand Up @@ -1337,7 +1337,7 @@ pub fn is_adjusted(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
cx.typeck_results().adjustments().get(e.hir_id).is_some()
}

/// Returns the pre-expansion span if is this comes from an expansion of the
/// Returns the pre-expansion span if this comes from an expansion of the
/// macro `name`.
/// See also [`is_direct_expn_of`].
#[must_use]
Expand All @@ -1364,7 +1364,8 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
/// of the macro `name`.
/// The difference with [`is_expn_of`] is that in
/// ```rust
/// # macro_rules! foo { ($e:tt) => { $e } }; macro_rules! bar { ($e:expr) => { $e } }
/// # macro_rules! foo { ($name:tt!$args:tt) => { $name!$args } }
/// # macro_rules! bar { ($e:expr) => { $e } }
/// foo!(bar!(42));
/// ```
/// `42` is considered expanded from `foo!` and `bar!` by `is_expn_of` but only
Expand Down Expand Up @@ -1905,7 +1906,9 @@ pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {

/// Check if parent of a hir node is a trait implementation block.
/// For example, `f` in
/// ```rust,ignore
/// ```rust
/// # struct S;
/// # trait Trait { fn f(); }
/// impl Trait for S {
/// fn f() {}
/// }
Expand Down
10 changes: 7 additions & 3 deletions clippy_utils/src/str_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ impl StrIndex {
/// Returns the index of the character after the first camel-case component of `s`.
///
/// ```
/// # use clippy_utils::str_utils::{camel_case_until, StrIndex};
/// assert_eq!(camel_case_until("AbcDef"), StrIndex::new(6, 6));
/// assert_eq!(camel_case_until("ABCD"), StrIndex::new(0, 0));
/// assert_eq!(camel_case_until("AbcDD"), StrIndex::new(3, 3));
Expand Down Expand Up @@ -55,9 +56,10 @@ pub fn camel_case_until(s: &str) -> StrIndex {
}
}

/// Returns index of the last camel-case component of `s`.
/// Returns index of the first camel-case component of `s`.
///
/// ```
/// # use clippy_utils::str_utils::{camel_case_start, StrIndex};
/// assert_eq!(camel_case_start("AbcDef"), StrIndex::new(0, 0));
/// assert_eq!(camel_case_start("abcDef"), StrIndex::new(3, 3));
/// assert_eq!(camel_case_start("ABCD"), StrIndex::new(4, 4));
Expand All @@ -69,9 +71,9 @@ pub fn camel_case_start(s: &str) -> StrIndex {
let char_count = s.chars().count();
let range = 0..char_count;
let mut iter = range.rev().zip(s.char_indices().rev());
if let Some((char_index, (_, first))) = iter.next() {
if let Some((_, (_, first))) = iter.next() {
if !first.is_lowercase() {
return StrIndex::new(char_index, s.len());
return StrIndex::new(char_count, s.len());
}
} else {
return StrIndex::new(char_count, s.len());
Expand Down Expand Up @@ -116,6 +118,7 @@ impl StrCount {
/// Returns the number of chars that match from the start
///
/// ```
/// # use clippy_utils::str_utils::{count_match_start, StrCount};
/// assert_eq!(count_match_start("hello_mouse", "hello_penguin"), StrCount::new(6, 6));
/// assert_eq!(count_match_start("hello_clippy", "bye_bugs"), StrCount::new(0, 0));
/// assert_eq!(count_match_start("hello_world", "hello_world"), StrCount::new(11, 11));
Expand All @@ -141,6 +144,7 @@ pub fn count_match_start(str1: &str, str2: &str) -> StrCount {
/// Returns the number of chars and bytes that match from the end
///
/// ```
/// # use clippy_utils::str_utils::{count_match_end, StrCount};
/// assert_eq!(count_match_end("hello_cat", "bye_cat"), StrCount::new(4, 4));
/// assert_eq!(count_match_end("if_item_thing", "enum_value"), StrCount::new(0, 0));
/// assert_eq!(count_match_end("Clippy", "Clippy"), StrCount::new(6, 6));
Expand Down

0 comments on commit fea103d

Please sign in to comment.