fix(match): fix warnings

This commit is contained in:
Federico Terzi 2021-10-05 22:06:39 +02:00
parent e112633509
commit 11fd7ce167
4 changed files with 27 additions and 23 deletions

View File

@ -91,10 +91,12 @@ where
"".to_string() "".to_string()
}; };
if let Event::Key { key: _, chars } = event { if let Event::Key {
if let Some(chars) = chars { key: _,
buffer.push_str(&chars); chars: Some(chars),
} } = event
{
buffer.push_str(&chars);
} }
// Keep the buffer length in check // Keep the buffer length in check
@ -259,13 +261,16 @@ mod tests {
RegexMatch::new(2, "multi\\((?P<name1>.*?),(?P<name2>.*?)\\)"), RegexMatch::new(2, "multi\\((?P<name1>.*?),(?P<name2>.*?)\\)"),
], ],
RegexMatcherOptions { RegexMatcherOptions {
max_buffer_size: 15 max_buffer_size: 15,
}, },
); );
assert_eq!( assert_eq!(
get_matches_after_str("say hello(mary)", &matcher), get_matches_after_str("say hello(mary)", &matcher),
vec![match_result(1, "hello(mary)", &[("name", "mary")])] vec![match_result(1, "hello(mary)", &[("name", "mary")])]
); );
assert_eq!(get_matches_after_str("hello(very long name over buffer)", &matcher), vec![]); assert_eq!(
get_matches_after_str("hello(very long name over buffer)", &matcher),
vec![]
);
} }
} }

View File

@ -203,10 +203,10 @@ impl<Id: Clone> RollingMatcher<Id> {
fn is_word_separator(&self, event: &Event) -> bool { fn is_word_separator(&self, event: &Event) -> bool {
match event { match event {
Event::Key { key, chars } => { Event::Key { key, chars } => {
if self.key_word_separators.contains(&key) { if self.key_word_separators.contains(key) {
true true
} else if let Some(char) = chars { } else if let Some(char) = chars {
self.char_word_separators.contains(&char) self.char_word_separators.contains(char)
} else { } else {
false false
} }

View File

@ -66,15 +66,13 @@ fn insert_items_recursively<Id>(id: Id, node: &mut MatcherTreeNode<Id>, items: &
return; return;
} }
let item = items.get(0).unwrap();
if items.len() == 1 { if items.len() == 1 {
let item = items.get(0).unwrap();
match item { match item {
RollingItem::WordSeparator => { RollingItem::WordSeparator => {
let mut new_matches = Vec::new(); let mut new_matches = Vec::new();
if let Some(node_ref) = node.word_separators.take() { if let Some(MatcherTreeRef::Matches(matches)) = node.word_separators.take() {
if let MatcherTreeRef::Matches(matches) = node_ref { new_matches.extend(matches);
new_matches.extend(matches);
}
} }
new_matches.push(id); new_matches.push(id);
node.word_separators = Some(MatcherTreeRef::Matches(new_matches)) node.word_separators = Some(MatcherTreeRef::Matches(new_matches))
@ -125,7 +123,6 @@ fn insert_items_recursively<Id>(id: Id, node: &mut MatcherTreeNode<Id>, items: &
} }
} }
} else { } else {
let item = items.get(0).unwrap();
match item { match item {
RollingItem::WordSeparator => match node.word_separators.as_mut() { RollingItem::WordSeparator => match node.word_separators.as_mut() {
Some(MatcherTreeRef::Node(next_node)) => { Some(MatcherTreeRef::Node(next_node)) => {

View File

@ -30,16 +30,18 @@ pub(crate) fn extract_string_from_events(
let mut right_separator = None; let mut right_separator = None;
for (i, (event, is_word_separator)) in events.iter().enumerate() { for (i, (event, is_word_separator)) in events.iter().enumerate() {
if let Event::Key { key: _, chars } = event { if let Event::Key {
if let Some(chars) = chars { key: _,
string.push_str(chars); chars: Some(chars),
} = event
{
string.push_str(chars);
if *is_word_separator { if *is_word_separator {
if i == 0 { if i == 0 {
left_separator = Some(chars.clone()); left_separator = Some(chars.clone());
} else if i == (events.len() - 1) { } else if i == (events.len() - 1) {
right_separator = Some(chars.clone()); right_separator = Some(chars.clone());
}
} }
} }
} }