mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 03:45:59 +00:00
SYNC: test for parseName + fix
This commit is contained in:
committed by
Diflow
parent
d3d97b5924
commit
0dd0125e9f
20
packages/tools/src/filterName.test.ts
Normal file
20
packages/tools/src/filterName.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
const { tokenizeBySearchFilter } = require('./filterName');
|
||||
|
||||
test('tokenize single token', () => {
|
||||
const tokenized = tokenizeBySearchFilter('Album', 'al');
|
||||
// console.log(JSON.stringify(tokenized, null, 2));
|
||||
expect(tokenized).toEqual([
|
||||
{ text: 'Al', isMatch: true },
|
||||
{ text: 'bum', isMatch: false },
|
||||
]);
|
||||
});
|
||||
|
||||
test('tokenize two tokens', () => {
|
||||
const tokenized = tokenizeBySearchFilter('Album', 'al,um');
|
||||
// console.log(JSON.stringify(tokenized, null, 2));
|
||||
expect(tokenized).toEqual([
|
||||
{ text: 'Al', isMatch: true },
|
||||
{ text: 'b', isMatch: false },
|
||||
{ text: 'um', isMatch: true },
|
||||
]);
|
||||
});
|
||||
@@ -118,7 +118,10 @@ export function filterNameCompoud(
|
||||
export function tokenizeBySearchFilter(text: string, filter: string): { text: string; isMatch: boolean }[] {
|
||||
const camelTokens = [];
|
||||
const stdTokens = [];
|
||||
for (const token of filter.split(/ ,/).map(x => x.trim())) {
|
||||
for (const token of filter
|
||||
.split(/[ ,]/)
|
||||
.map(x => x.trim())
|
||||
.filter(x => x.length > 0)) {
|
||||
if (token.replace(/[A-Z]/g, '').length == 0) {
|
||||
camelTokens.push(token);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user