datasource.test.ts 893 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { parseQuery } from './datasource';
  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. });