refactor(match): remove preserve_case_markers option as it's not needed

This commit is contained in:
Federico Terzi 2021-04-19 22:02:23 +02:00
parent 82096ad9fa
commit 1fad2039d6
2 changed files with 12 additions and 37 deletions

View File

@ -230,7 +230,12 @@ mod tests {
} }
} }
fn match_result_with_sep<Id: Default>(id: Id, trigger: &str, left: Option<&str>, right: Option<&str>) -> MatchResult<Id> { fn match_result_with_sep<Id: Default>(
id: Id,
trigger: &str,
left: Option<&str>,
right: Option<&str>,
) -> MatchResult<Id> {
MatchResult { MatchResult {
id, id,
trigger: trigger.to_string(), trigger: trigger.to_string(),
@ -321,7 +326,6 @@ mod tests {
"arty", "arty",
&StringMatchOptions { &StringMatchOptions {
case_insensitive: true, case_insensitive: true,
preserve_case_markers: true,
..Default::default() ..Default::default()
}, },
), ),
@ -352,6 +356,9 @@ mod tests {
get_matches_after_str("arTY", &matcher), get_matches_after_str("arTY", &matcher),
vec![match_result(3, "arTY")] vec![match_result(3, "arTY")]
); );
assert_eq!(get_matches_after_str("ARTY", &matcher), vec![]); assert_eq!(
get_matches_after_str("ARTY", &matcher),
vec![match_result(3, "ARTY")]
);
} }
} }

View File

@ -49,15 +49,9 @@ impl<Id> RollingMatch<Id> {
items.push(RollingItem::WordSeparator); items.push(RollingItem::WordSeparator);
} }
for (index, c) in string.chars().enumerate() { for c in string.chars() {
if opt.case_insensitive { if opt.case_insensitive {
// If preserve case markers is true, we want to keep the first two chars
// as case-sensitive. This is needed to implement the "propagate_case" option.
if opt.preserve_case_markers && index < 2 {
items.push(RollingItem::Char(c.to_string()))
} else {
items.push(RollingItem::CharInsensitive(c.to_string())) items.push(RollingItem::CharInsensitive(c.to_string()))
}
} else { } else {
items.push(RollingItem::Char(c.to_string())) items.push(RollingItem::Char(c.to_string()))
} }
@ -80,7 +74,6 @@ impl<Id> RollingMatch<Id> {
pub struct StringMatchOptions { pub struct StringMatchOptions {
pub case_insensitive: bool, pub case_insensitive: bool,
pub preserve_case_markers: bool,
pub left_word: bool, pub left_word: bool,
pub right_word: bool, pub right_word: bool,
} }
@ -89,7 +82,6 @@ impl Default for StringMatchOptions {
fn default() -> Self { fn default() -> Self {
Self { Self {
case_insensitive: false, case_insensitive: false,
preserve_case_markers: false,
left_word: false, left_word: false,
right_word: false, right_word: false,
} }
@ -186,28 +178,4 @@ mod tests {
} }
) )
} }
#[test]
fn test_match_from_string_preserve_case_markers() {
assert_eq!(
RollingMatch::from_string(
1,
"test",
&StringMatchOptions {
case_insensitive: true,
preserve_case_markers: true,
..Default::default()
}
),
RollingMatch {
id: 1,
items: vec![
RollingItem::Char("t".to_string()),
RollingItem::Char("e".to_string()),
RollingItem::CharInsensitive("s".to_string()),
RollingItem::CharInsensitive("t".to_string()),
]
}
)
}
} }