code.gitea.io/gitea@v1.21.7/web_src/js/features/repo-findfile.test.js (about)

     1  import {strSubMatch, calcMatchedWeight, filterRepoFilesWeighted} from './repo-findfile.js';
     2  
     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  
    13      expect(strSubMatch('ABc', 'ac')).toEqual(['', 'A', 'B', 'c']);
    14      expect(strSubMatch('abC', 'ac')).toEqual(['', 'a', 'b', 'C']);
    15  
    16      expect(strSubMatch('aabbcc', 'abc')).toEqual(['', 'a', 'a', 'b', 'b', 'c', 'c']);
    17      expect(strSubMatch('the/directory', 'hedir')).toEqual(['t', 'he', '/', 'dir', 'ectory']);
    18    });
    19  
    20    test('calcMatchedWeight', () => {
    21      expect(calcMatchedWeight(['a', 'b', 'c', 'd']) < calcMatchedWeight(['a', 'bc', 'c'])).toBeTruthy();
    22    });
    23  
    24    test('filterRepoFilesWeighted', () => {
    25      // the first matched result should always be the "word.txt"
    26      let res = filterRepoFilesWeighted(['word.txt', 'we-got-result.dat'], 'word');
    27      expect(res).toHaveLength(2);
    28      expect(res[0].matchResult).toEqual(['', 'word', '.txt']);
    29  
    30      res = filterRepoFilesWeighted(['we-got-result.dat', 'word.txt'], 'word');
    31      expect(res).toHaveLength(2);
    32      expect(res[0].matchResult).toEqual(['', 'word', '.txt']);
    33    });
    34  });