mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 08:46:35 +00:00
Add tests for fuzzy sequence matcher (#7328)
This commit is contained in:
parent
5de225d5d4
commit
ddcf89e6a2
52
test-mocha/common/string/sequence_matching.test.ts
Normal file
52
test-mocha/common/string/sequence_matching.test.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { assert } from "chai";
|
||||
|
||||
import { fuzzySequentialMatch } from "../../../src/common/string/sequence_matching";
|
||||
|
||||
describe("fuzzySequentialMatch", () => {
|
||||
const entityId = "automation.ticker";
|
||||
|
||||
const shouldMatchEntity = [
|
||||
"",
|
||||
"automation.ticker",
|
||||
"automation.ticke",
|
||||
"automation.",
|
||||
"au",
|
||||
"automationticker",
|
||||
"tion.tick",
|
||||
"ticker",
|
||||
"automation.r",
|
||||
"tick",
|
||||
"aumatick",
|
||||
"aion.tck",
|
||||
"ioticker",
|
||||
"atmto.ikr",
|
||||
"uoaintce",
|
||||
"au.tce",
|
||||
"tomaontkr",
|
||||
];
|
||||
|
||||
const shouldNotMatchEntity = [
|
||||
" ",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"automation.tickerz",
|
||||
"automation. ticke",
|
||||
"1",
|
||||
"noitamotua",
|
||||
];
|
||||
|
||||
describe(`Entity '${entityId}'`, () => {
|
||||
for (const goodFilter of shouldMatchEntity) {
|
||||
it(`matches with '${goodFilter}'`, () => {
|
||||
const res = fuzzySequentialMatch(goodFilter, entityId);
|
||||
assert.equal(res, true);
|
||||
});
|
||||
}
|
||||
|
||||
for (const badFilter of shouldNotMatchEntity) {
|
||||
it(`fails to match with '${badFilter}'`, () => {
|
||||
const res = fuzzySequentialMatch(badFilter, entityId);
|
||||
assert.equal(res, false);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user