From 8ed723bb1f988d0fb624817bcb7e10da192bcbd9 Mon Sep 17 00:00:00 2001 From: dswij Date: Thu, 23 Dec 2021 11:32:04 +0800 Subject: [PATCH] Update str_utils test --- clippy_utils/src/str_utils.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/clippy_utils/src/str_utils.rs b/clippy_utils/src/str_utils.rs index daa816d211e..7200baf5b3c 100644 --- a/clippy_utils/src/str_utils.rs +++ b/clippy_utils/src/str_utils.rs @@ -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(); @@ -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 { let mut result = Vec::new(); @@ -138,6 +142,7 @@ pub fn camel_case_indexes(s: &str) -> Vec { /// 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> { @@ -288,17 +293,16 @@ fn until_caps() { 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]