Skip to content

Commit

Permalink
Update str_utils test
Browse files Browse the repository at this point in the history
  • Loading branch information
dswij committed Dec 25, 2021
1 parent df2e4d1 commit 8ed723b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions clippy_utils/src/str_utils.rs
Expand Up @@ -74,8 +74,9 @@ pub fn camel_case_start(s: &str) -> StrIndex {
/// Returns `StrIndex` of the last camel-case component of `s[idx..]`.
///
/// ```
/// assert_eq!(camel_case_start("AbcDef", 0), StrIndex::new(0, 0));
/// assert_eq!(camel_case_start("AbcDef", 1), StrIndex::new(3, 3));
/// # use clippy_utils::str_utils::{camel_case_start_from_idx, StrIndex};
/// assert_eq!(camel_case_start_from_idx("AbcDef", 0), StrIndex::new(0, 0));
/// assert_eq!(camel_case_start_from_idx("AbcDef", 1), StrIndex::new(3, 3));
/// ```
pub fn camel_case_start_from_idx(s: &str, start_idx: usize) -> StrIndex {
let char_count = s.chars().count();
Expand Down Expand Up @@ -119,7 +120,10 @@ pub fn camel_case_start_from_idx(s: &str, start_idx: usize) -> StrIndex {
/// Get the indexes of camel case components of a string `s`
///
/// ```
/// assert_eq!(camel_case_indexes("AbcDef"), vec![StrIndex::new(0, 0), StrIndex::new(3, 3)])
/// # use clippy_utils::str_utils::{camel_case_indexes, StrIndex};
/// assert_eq!(camel_case_indexes("AbcDef"), vec![StrIndex::new(0, 0), StrIndex::new(3, 3),
/// StrIndex::new(6, 6)]);
/// assert_eq!(camel_case_indexes("abcDef"), vec![StrIndex::new(3, 3), StrIndex::new(6, 6)]);
/// ```
pub fn camel_case_indexes(s: &str) -> Vec<StrIndex> {
let mut result = Vec::new();
Expand All @@ -138,6 +142,7 @@ pub fn camel_case_indexes(s: &str) -> Vec<StrIndex> {
/// Split camel case string into a vector of its components
///
/// ```
/// # use clippy_utils::str_utils::{camel_case_split, StrIndex};
/// assert_eq!(camel_case_split("AbcDef"), vec!["Abc", "Def"]);
/// ```
pub fn camel_case_split(s: &str) -> Vec<&str> {
Expand Down Expand Up @@ -288,17 +293,16 @@ mod test {
assert_eq!(camel_case_until("ABCD"), StrIndex::new(0, 0));
}

#[test]
fn camel_case_start_from_idx_full() {
assert_eq!(camel_case_start_from_idx("AbcDef", 0), StrIndex::new(0, 0));
assert_eq!(camel_case_start_from_idx("AbcDef", 1), StrIndex::new(3, 3));
assert_eq!(camel_case_start_from_idx("AbcDef", 4), StrIndex::new(6, 6));
}

#[test]
fn camel_case_indexes_full() {
assert_eq!(
camel_case_indexes("AbcDef"),
vec![StrIndex::new(0, 0), StrIndex::new(3, 3)]
);
assert_eq!(
camel_case_indexes("abcDef"),
vec![StrIndex::new(0, 0), StrIndex::new(3, 3)]
);
assert_eq!(camel_case_indexes("Abc\u{f6}\u{f6}DD"), vec![StrIndex::new(5, 7)]);
assert_eq!(camel_case_indexes("Abc\u{f6}\u{f6}DD"), vec![StrIndex::new(7, 9)]);
}

#[test]
Expand Down

0 comments on commit 8ed723b

Please sign in to comment.