You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo-findfile.test.js 1.5KB

12345678910111213141516171819202122232425262728293031323334
  1. import {strSubMatch, calcMatchedWeight, filterRepoFilesWeighted} from './repo-findfile.js';
  2. describe('Repo Find Files', () => {
  3. test('strSubMatch', () => {
  4. expect(strSubMatch('abc', '')).toEqual(['abc']);
  5. expect(strSubMatch('abc', 'a')).toEqual(['', 'a', 'bc']);
  6. expect(strSubMatch('abc', 'b')).toEqual(['a', 'b', 'c']);
  7. expect(strSubMatch('abc', 'c')).toEqual(['ab', 'c']);
  8. expect(strSubMatch('abc', 'ac')).toEqual(['', 'a', 'b', 'c']);
  9. expect(strSubMatch('abc', 'z')).toEqual(['abc']);
  10. expect(strSubMatch('abc', 'az')).toEqual(['abc']);
  11. expect(strSubMatch('ABc', 'ac')).toEqual(['', 'A', 'B', 'c']);
  12. expect(strSubMatch('abC', 'ac')).toEqual(['', 'a', 'b', 'C']);
  13. expect(strSubMatch('aabbcc', 'abc')).toEqual(['', 'a', 'a', 'b', 'b', 'c', 'c']);
  14. expect(strSubMatch('the/directory', 'hedir')).toEqual(['t', 'he', '/', 'dir', 'ectory']);
  15. });
  16. test('calcMatchedWeight', () => {
  17. expect(calcMatchedWeight(['a', 'b', 'c', 'd']) < calcMatchedWeight(['a', 'bc', 'c'])).toBeTruthy();
  18. });
  19. test('filterRepoFilesWeighted', () => {
  20. // the first matched result should always be the "word.txt"
  21. let res = filterRepoFilesWeighted(['word.txt', 'we-got-result.dat'], 'word');
  22. expect(res).toHaveLength(2);
  23. expect(res[0].matchResult).toEqual(['', 'word', '.txt']);
  24. res = filterRepoFilesWeighted(['we-got-result.dat', 'word.txt'], 'word');
  25. expect(res).toHaveLength(2);
  26. expect(res[0].matchResult).toEqual(['', 'word', '.txt']);
  27. });
  28. });