flamegraphSearch.spec.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {FlamegraphFrame} from 'sentry/utils/profiling/flamegraphFrame';
  2. import {
  3. searchFrameFzf,
  4. searchFrameRegExp,
  5. } from './flamegraph/flamegraphToolbar/flamegraphSearch';
  6. const f = (name: string) => {
  7. return {
  8. frame: {
  9. name,
  10. },
  11. } as FlamegraphFrame;
  12. };
  13. describe('fzf', () => {
  14. it('matches only first occurrence', () => {
  15. expect(searchFrameFzf(f('foofoo'), new Map(), 'foo')).toMatchObject({
  16. start: 0,
  17. end: 3,
  18. matches: [[0, 3]],
  19. });
  20. });
  21. it('prefers matches at start', () => {
  22. expect(searchFrameFzf(f('f'), new Map(), 'f').score).toBeGreaterThan(
  23. searchFrameFzf(f('of'), new Map(), 'f').score
  24. );
  25. });
  26. it('penalizes gaps', () => {
  27. expect(searchFrameFzf(f('f oo'), new Map(), 'foo').score).toBeLessThan(
  28. searchFrameFzf(f('foo'), new Map(), 'foo').score
  29. );
  30. });
  31. it('narrows down indices on backtracking', () => {
  32. // https://github.com/junegunn/fzf/blob/f81feb1e69e5cb75797d50817752ddfe4933cd68/src/algo/algo.go#L13
  33. expect(searchFrameFzf(f('a_____b___abc__'), new Map(), 'abc').matches).toEqual([
  34. [10, 13],
  35. ]);
  36. });
  37. });
  38. describe('regexp', () => {
  39. it('finds all matches', () => {
  40. expect(searchFrameRegExp(f('foofoo'), new Map(), 'foo', 'g')).toEqual([0, 3]);
  41. });
  42. });