fix contains matching & bump version
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
LordMZTE 2021-07-10 16:14:43 +02:00
parent 0e4664ceeb
commit 58569bae3f
3 changed files with 17 additions and 11 deletions

View file

@ -1,4 +1,3 @@
# 0.2.3
- added "matches" propery for memes
- added tests for meme matching
- added "wtf" and "wtuff" commands
# 0.2.4
- fix match = "contains" commands matching when keyword is at the start of message, and there are invalid characters after it.
- add tests

View file

@ -1,6 +1,6 @@
[package]
name = "ruff"
version = "0.2.3"
version = "0.2.4"
authors = ["LordMZTE <lord@mzte.de>"]
edition = "2018"

View file

@ -33,17 +33,17 @@ impl Meme {
Matcher::Contains => msg
.match_indices(&self.keyword)
.map(|(idx, subs)| {
idx == 0
(idx == 0
|| msg
.chars()
.nth(idx - 1)
.map(|c| ALLOWED_SPACES.contains(c))
.unwrap_or(true))
&& msg
.chars()
.nth(idx + subs.len())
.map(|c| ALLOWED_SPACES.contains(c))
.unwrap_or(true)
&& msg
.chars()
.nth(idx + subs.len())
.map(|c| ALLOWED_SPACES.contains(c))
.unwrap_or(true)
})
.any(|b| b),
}
@ -85,6 +85,9 @@ mod tests {
assert!(!meme.matches("xxx"));
assert!(!meme.matches("testxxx"));
assert!(!meme.matches("xxxtestxxx"));
assert!(!meme.matches("xxxtest xxx"));
assert!(!meme.matches("xxx testxxx"));
assert!(meme.matches("test"));
assert!(meme.matches("test xxx"));
assert!(meme.matches("test; xxx"));
@ -103,6 +106,10 @@ mod tests {
assert!(!meme.matches("xxx"));
assert!(!meme.matches("xxxtestxxx"));
assert!(!meme.matches("xxxtest xxx"));
assert!(!meme.matches("xxx testxxx"));
assert!(!meme.matches("xxxtest"));
assert!(!meme.matches("testxxx"));
assert!(meme.matches("xxx test xxx"));
assert!(meme.matches("xxx,test.xxx"));
assert!(meme.matches("xxx,TEST.xxx"));