mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-25 04:47:59 +01:00
3590be1429
* match_query: unit test and rewrite for TypeScript * match_query: use new type for parse errors * match_query: avoid exceptional control flow in date parsing
36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import { makeLiteralMatcher } from '../literal';
|
|
|
|
describe('Literal field parsing', () => {
|
|
it('should handle exact matching in arrayed fields', () => {
|
|
const matcher = makeLiteralMatcher('safe', 0, false);
|
|
expect(matcher('safe, solo', 'tags', 0)).toBe(true);
|
|
expect(matcher('solo', 'tags', 0)).toBe(false);
|
|
});
|
|
|
|
it('should handle exact matching in non-arrayed fields', () => {
|
|
const matcher = makeLiteralMatcher('safe', 0, false);
|
|
expect(matcher('safe, solo', 'description', 0)).toBe(false);
|
|
expect(matcher('safe', 'description', 0)).toBe(true);
|
|
expect(matcher('solo', 'description', 0)).toBe(false);
|
|
});
|
|
|
|
it('should handle fuzzy matching based on normalized edit distance', () => {
|
|
const matcher = makeLiteralMatcher('fluttersho', 0.8, false);
|
|
expect(matcher('fluttershy', 'tags', 0)).toBe(true);
|
|
expect(matcher('rarity', 'tags', 0)).toBe(false);
|
|
});
|
|
|
|
it('should handle fuzzy matching based on raw edit distance', () => {
|
|
const matcher = makeLiteralMatcher('fluttersho', 1, false);
|
|
expect(matcher('fluttershy', 'tags', 0)).toBe(true);
|
|
expect(matcher('rarity', 'tags', 0)).toBe(false);
|
|
});
|
|
|
|
it('should handle wildcard matching', () => {
|
|
const matcher = makeLiteralMatcher('fl?tter*', 0, true);
|
|
expect(matcher('fluttershy', 'tags', 0)).toBe(true);
|
|
expect(matcher('flitter', 'tags', 0)).toBe(true);
|
|
expect(matcher('rainbow dash', 'tags', 0)).toBe(false);
|
|
expect(matcher('gentle flutter', 'tags', 0)).toBe(false);
|
|
});
|
|
});
|