|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | + |
| 3 | +// Simple function to test the query transformation logic |
| 4 | +// We'll extract just the normalization part to test it separately |
| 5 | +const normalizeQueryOperators = (query: string): string => { |
| 6 | + return query |
| 7 | + // Replace standalone uppercase OR with lowercase or |
| 8 | + .replace(/\bOR\b/g, 'or') |
| 9 | + // Replace standalone uppercase AND with lowercase and (though AND is implicit in Zoekt) |
| 10 | + .replace(/\bAND\b/g, 'and'); |
| 11 | +}; |
| 12 | + |
| 13 | +describe('Query transformation', () => { |
| 14 | + describe('normalizeQueryOperators', () => { |
| 15 | + it('should convert uppercase OR to lowercase or', () => { |
| 16 | + expect(normalizeQueryOperators('file:yarn.lock OR file:package.json')) |
| 17 | + .toBe('file:yarn.lock or file:package.json'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should convert uppercase AND to lowercase and', () => { |
| 21 | + expect(normalizeQueryOperators('foo AND bar')) |
| 22 | + .toBe('foo and bar'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should handle parenthesized expressions', () => { |
| 26 | + expect(normalizeQueryOperators('(file:yarn.lock OR file:package.json)')) |
| 27 | + .toBe('(file:yarn.lock or file:package.json)'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should handle complex queries with multiple operators', () => { |
| 31 | + expect(normalizeQueryOperators('(file:*.json OR file:*.lock) AND content:react')) |
| 32 | + .toBe('(file:*.json or file:*.lock) and content:react'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should not affect lowercase operators', () => { |
| 36 | + expect(normalizeQueryOperators('file:yarn.lock or file:package.json')) |
| 37 | + .toBe('file:yarn.lock or file:package.json'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should not affect OR/AND when part of other words', () => { |
| 41 | + expect(normalizeQueryOperators('ORDER BY something')) |
| 42 | + .toBe('ORDER BY something'); |
| 43 | + |
| 44 | + expect(normalizeQueryOperators('ANDROID app')) |
| 45 | + .toBe('ANDROID app'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should handle mixed case queries', () => { |
| 49 | + expect(normalizeQueryOperators('file:src OR file:test and lang:typescript')) |
| 50 | + .toBe('file:src or file:test and lang:typescript'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should handle multiple ORs and ANDs', () => { |
| 54 | + expect(normalizeQueryOperators('A OR B OR C AND D AND E')) |
| 55 | + .toBe('A or B or C and D and E'); |
| 56 | + }); |
| 57 | + }); |
| 58 | +}); |
0 commit comments