fix contains matching & bump version
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
0e4664ceeb
commit
58569bae3f
|
@ -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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ruff"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
authors = ["LordMZTE <lord@mzte.de>"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
19
src/meme.rs
19
src/meme.rs
|
@ -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"));
|
||||
|
|
Loading…
Reference in a new issue