|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { quoteIfSpecialCharacters } from './helpers.svelte'; |
| 4 | + |
| 5 | +describe('helpers.svelte', () => { |
| 6 | + it('quoteIfSpecialCharacters handles tabs and newlines', () => { |
| 7 | + expect(quoteIfSpecialCharacters('foo\tbar')).toBe('"foo\tbar"'); |
| 8 | + expect(quoteIfSpecialCharacters('foo\nbar')).toBe('"foo\nbar"'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('quoteIfSpecialCharacters handles empty string and undefined/null', () => { |
| 12 | + expect(quoteIfSpecialCharacters('')).toBe(''); |
| 13 | + expect(quoteIfSpecialCharacters(undefined)).toBeUndefined(); |
| 14 | + expect(quoteIfSpecialCharacters(null)).toBeNull(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('quoteIfSpecialCharacters quotes strings with multiple spaces', () => { |
| 18 | + expect(quoteIfSpecialCharacters('foo bar')).toBe('"foo bar"'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('quoteIfSpecialCharacters quotes strings with leading and trailing spaces', () => { |
| 22 | + expect(quoteIfSpecialCharacters(' foo bar ')).toBe('"foo bar"'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('quoteIfSpecialCharacters does not alter already quoted strings', () => { |
| 26 | + expect(quoteIfSpecialCharacters('"foo bar"')).toBe('"foo bar"'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('quoteIfSpecialCharacters handles strings with only spaces', () => { |
| 30 | + expect(quoteIfSpecialCharacters(' ')).toBe(''); |
| 31 | + }); |
| 32 | + |
| 33 | + it('quoteIfSpecialCharacters handles strings with unicode characters', () => { |
| 34 | + expect(quoteIfSpecialCharacters('фывапр')).toBe('фывапр'); // unicode is not special |
| 35 | + }); |
| 36 | + |
| 37 | + it('quoteIfSpecialCharacters handles strings with emojis', () => { |
| 38 | + expect(quoteIfSpecialCharacters('foo😊bar')).toBe('foo😊bar'); // emoji is not special |
| 39 | + }); |
| 40 | + |
| 41 | + it('quoteIfSpecialCharacters quotes all Lucene special characters', () => { |
| 42 | + const luceneSpecials = ['+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '\\', '/']; |
| 43 | + for (const char of luceneSpecials) { |
| 44 | + expect(quoteIfSpecialCharacters(char)).toBe(`"${char}"`); |
| 45 | + expect(quoteIfSpecialCharacters(`foo${char}bar`)).toBe(`"foo${char}bar"`); |
| 46 | + } |
| 47 | + }); |
| 48 | +}); |
0 commit comments