text.test.ts 938 B

123456789101112131415161718192021222324
  1. import { findMatchesInText } from './text';
  2. describe('findMatchesInText()', () => {
  3. it('gets no matches for when search and or line are empty', () => {
  4. expect(findMatchesInText('', '')).toEqual([]);
  5. expect(findMatchesInText('foo', '')).toEqual([]);
  6. expect(findMatchesInText('', 'foo')).toEqual([]);
  7. });
  8. it('gets no matches for unmatched search string', () => {
  9. expect(findMatchesInText('foo', 'bar')).toEqual([]);
  10. });
  11. it('gets matches for matched search string', () => {
  12. expect(findMatchesInText('foo', 'foo')).toEqual([{ length: 3, start: 0, text: 'foo', end: 3 }]);
  13. expect(findMatchesInText(' foo ', 'foo')).toEqual([{ length: 3, start: 1, text: 'foo', end: 4 }]);
  14. });
  15. expect(findMatchesInText(' foo foo bar ', 'foo|bar')).toEqual([
  16. { length: 3, start: 1, text: 'foo', end: 4 },
  17. { length: 3, start: 5, text: 'foo', end: 8 },
  18. { length: 3, start: 9, text: 'bar', end: 12 },
  19. ]);
  20. });