Test clippy_utils in CI

This makes sure that the tests in clippy_utils are run in CI.

When looking into this I discovered that two tests were failing and
multiple doc tests were failing. This fixes those tests and enables a
few more doc tests.
This commit is contained in:
flip1995
2021-12-20 19:56:06 +01:00
parent 790513056f
commit eb47398773
4 changed files with 25 additions and 10 deletions

View File

@@ -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));
@@ -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));
@@ -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());
@@ -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));
@@ -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));