query_utils.test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { parseQuery } from './query_utils';
  2. describe('parseQuery', () => {
  3. it('returns empty for empty string', () => {
  4. expect(parseQuery('')).toEqual({
  5. query: '',
  6. regexp: '',
  7. });
  8. });
  9. it('returns regexp for strings without query', () => {
  10. expect(parseQuery('test')).toEqual({
  11. query: '',
  12. regexp: 'test',
  13. });
  14. });
  15. it('returns query for strings without regexp', () => {
  16. expect(parseQuery('{foo="bar"}')).toEqual({
  17. query: '{foo="bar"}',
  18. regexp: '',
  19. });
  20. });
  21. it('returns query for strings with query and search string', () => {
  22. expect(parseQuery('x {foo="bar"}')).toEqual({
  23. query: '{foo="bar"}',
  24. regexp: 'x',
  25. });
  26. });
  27. it('returns query for strings with query and regexp', () => {
  28. expect(parseQuery('{foo="bar"} x|y')).toEqual({
  29. query: '{foo="bar"}',
  30. regexp: 'x|y',
  31. });
  32. });
  33. it('returns query for selector with two labels', () => {
  34. expect(parseQuery('{foo="bar", baz="42"}')).toEqual({
  35. query: '{foo="bar", baz="42"}',
  36. regexp: '',
  37. });
  38. });
  39. it('returns query and regexp with quantifiers', () => {
  40. expect(parseQuery('{foo="bar"} \\.java:[0-9]{1,5}')).toEqual({
  41. query: '{foo="bar"}',
  42. regexp: '\\.java:[0-9]{1,5}',
  43. });
  44. expect(parseQuery('\\.java:[0-9]{1,5} {foo="bar"}')).toEqual({
  45. query: '{foo="bar"}',
  46. regexp: '\\.java:[0-9]{1,5}',
  47. });
  48. });
  49. });