Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): Support multiple brackets in rune matcher (#3608)
Marc Bachmanncee2079de647
diff --git a/harper-core/src/spell/rune/matcher.rs b/harper-core/src/spell/rune/matcher.rsindex b3a6bb3d6..4e9e8b42c 100644--- a/harper-core/src/spell/rune/matcher.rs+++ b/harper-core/src/spell/rune/matcher.rs@@ -23,9 +23,10 @@ impl Matcher {match c {'[' => {- let close_idx = source[idx..]- .find(']')- .ok_or(Error::UnmatchedBracket { index: idx })?;+ let close_idx = idx+ + source[idx..]+ .find(']')+ .ok_or(Error::UnmatchedBracket { index: idx })?;let bracket_contents = &source[idx + 1..close_idx];@@ -144,6 +145,20 @@ mod tests {)}+ #[test]+ fn parses_multi_brackets() {+ let matcher = Matcher::parse("u[xy]a[^z]").unwrap();+ assert_eq!(+ matcher.operators,+ vec![+ Operator::Literal('u'),+ Operator::MatchOne(vec!['x', 'y']),+ Operator::Literal('a'),+ Operator::MatchNone(vec!['z']),+ ]+ );+ }+#[test]fn matches_vowels() {let matcher = Matcher::parse("[aeiou]").unwrap();@@ -155,6 +170,16 @@ mod tests {assert!(matcher.matches(&['u']));}+ #[test]+ fn matches_multiple_bracket_vowels() {+ let matcher = Matcher::parse("u[xy]a[^z]").unwrap();++ assert!(matcher.matches(&['u', 'x', 'a', 'q']));+ assert!(matcher.matches(&['u', 'y', 'a', 'y']));+ assert!(!matcher.matches(&['u', 'e', 'a', 'e']));+ assert!(!matcher.matches(&['u', 'x', 'a', 'z']));+ }+#[test]fn round_trip() {let source = "[^aeiou]a.s";@@ -162,4 +187,11 @@ mod tests {assert_eq!(matcher.to_string(), source);}++ #[test]+ fn round_trip_multiple_brackets() {+ let source = "über[^e]gegen[^eü]";+ let matcher = Matcher::parse(source).unwrap();+ assert_eq!(matcher.to_string(), source);+ }}