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

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