softdevteam / fm Goto Github PK
View Code? Open in Web Editor NEWNon-backtracking fuzzy text matching
License: Other
Non-backtracking fuzzy text matching
License: Other
Here's an in interesting one.
assert!(helper("$1 $1 $1", "a a a"));
assert!(helper("$1 $2 $3", "a a a"));
Using the same name matchers as in the repo.
I expected the latter to fail because I wasn't expecting different names to be allowed to assume the same value.
Now a real world example. Here's what a TIR test looks like:
assert_tir(
"live($a)\n\
$a = call(add6, [1u64, 1u64, 1u64, 1u64, 1u64, 1u64])\n\
dead($a)",
&tir_trace,
);
assert_tir()
just stringifies the TIR trace and tries to match the given pattern using the following name matchers:
let ptn_re = Regex::new(r"\$.+?\b").unwrap();
let text_re = Regex::new(r"\$?.+?\b").unwrap(); // Optional `$` prefix.
Then to test a failing match, I naively flipped $a
on the first line of the pattern to $c
and was surprised to see it matched. Of course, it's ok for both $a
and $c
to match the same content.
But should it be? Perhaps I want to know that the variable used in live
is distinct from the one in the call
and the dead
.
I added the test:
assert_eq!(helper("...\nline2\nline3\nline4\n", "line1\nline2\nline3\nbadgers\nline5"), 4);
Which gives fails, as the failure line reported is 3
, not as I expected 4
. I expected 4
because the first line in the text which doesn't match is badgers
on line 4.
Did I misunderstand something, or is that a bug?
@vext01 and I triggered a bug in FM. If your pattern has two consecutive wildcards with a newline in between FM crashes:
thread 'tests::defaults' panicked at 'begin <= end (3 <= 0) when slicing `...`', src/lib.rs:357:28
See test:
diff --git a/src/lib.rs b/src/lib.rs
index c4fbca4..1c83515 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -523,6 +523,7 @@ mod tests {
FMatcher::new(ptn).unwrap().matches(text).is_ok()
}
assert!(helper("", ""));
+ assert!(helper("...\n...", ""));
assert!(helper("\n", ""));
assert!(helper("", "\n"));
assert!(helper("a", "a"));
I guess it doesn't make sense to do this in a pattern, but maybe a user friendly message would help here.
I've added the following case to the name matcher test:
assert!(helper("$1", "$2"));
The regexs in the helper remain the same:
let nameptn_re = Regex::new(r"\$.+?\b").unwrap();
let name_re = Regex::new(r".+?\b").unwrap();
The FM matcher fails to match this.
I was expecting this to match, because the following assertions are true:
assert!(Regex::new(r"\$.+?\b").unwrap().is_match("$1"));
assert!(Regex::new(r".+?\b").unwrap().is_match("$2"));
I'm not sure if my expectations are wrong, or if it's a bug.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.