|
@@ -1,56 +1,87 @@
|
|
|
-import { parseQuery } from './query_utils';
|
|
|
|
|
|
|
+import { parseQuery, getHighlighterExpressionsFromQuery } from './query_utils';
|
|
|
|
|
+import { LokiExpression } from './types';
|
|
|
|
|
|
|
|
describe('parseQuery', () => {
|
|
describe('parseQuery', () => {
|
|
|
it('returns empty for empty string', () => {
|
|
it('returns empty for empty string', () => {
|
|
|
expect(parseQuery('')).toEqual({
|
|
expect(parseQuery('')).toEqual({
|
|
|
query: '',
|
|
query: '',
|
|
|
regexp: '',
|
|
regexp: '',
|
|
|
- });
|
|
|
|
|
|
|
+ } as LokiExpression);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('returns regexp for strings without query', () => {
|
|
it('returns regexp for strings without query', () => {
|
|
|
expect(parseQuery('test')).toEqual({
|
|
expect(parseQuery('test')).toEqual({
|
|
|
- query: '',
|
|
|
|
|
- regexp: '(?i)test',
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ query: 'test',
|
|
|
|
|
+ regexp: '',
|
|
|
|
|
+ } as LokiExpression);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('returns query for strings without regexp', () => {
|
|
it('returns query for strings without regexp', () => {
|
|
|
expect(parseQuery('{foo="bar"}')).toEqual({
|
|
expect(parseQuery('{foo="bar"}')).toEqual({
|
|
|
query: '{foo="bar"}',
|
|
query: '{foo="bar"}',
|
|
|
regexp: '',
|
|
regexp: '',
|
|
|
- });
|
|
|
|
|
|
|
+ } as LokiExpression);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('returns query for strings with query and search string', () => {
|
|
it('returns query for strings with query and search string', () => {
|
|
|
expect(parseQuery('x {foo="bar"}')).toEqual({
|
|
expect(parseQuery('x {foo="bar"}')).toEqual({
|
|
|
query: '{foo="bar"}',
|
|
query: '{foo="bar"}',
|
|
|
regexp: '(?i)x',
|
|
regexp: '(?i)x',
|
|
|
- });
|
|
|
|
|
|
|
+ } as LokiExpression);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('returns query for strings with query and regexp', () => {
|
|
it('returns query for strings with query and regexp', () => {
|
|
|
expect(parseQuery('{foo="bar"} x|y')).toEqual({
|
|
expect(parseQuery('{foo="bar"} x|y')).toEqual({
|
|
|
query: '{foo="bar"}',
|
|
query: '{foo="bar"}',
|
|
|
regexp: '(?i)x|y',
|
|
regexp: '(?i)x|y',
|
|
|
- });
|
|
|
|
|
|
|
+ } as LokiExpression);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('returns query for selector with two labels', () => {
|
|
it('returns query for selector with two labels', () => {
|
|
|
expect(parseQuery('{foo="bar", baz="42"}')).toEqual({
|
|
expect(parseQuery('{foo="bar", baz="42"}')).toEqual({
|
|
|
query: '{foo="bar", baz="42"}',
|
|
query: '{foo="bar", baz="42"}',
|
|
|
regexp: '',
|
|
regexp: '',
|
|
|
- });
|
|
|
|
|
|
|
+ } as LokiExpression);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('returns query and regexp with quantifiers', () => {
|
|
it('returns query and regexp with quantifiers', () => {
|
|
|
expect(parseQuery('{foo="bar"} \\.java:[0-9]{1,5}')).toEqual({
|
|
expect(parseQuery('{foo="bar"} \\.java:[0-9]{1,5}')).toEqual({
|
|
|
query: '{foo="bar"}',
|
|
query: '{foo="bar"}',
|
|
|
regexp: '(?i)\\.java:[0-9]{1,5}',
|
|
regexp: '(?i)\\.java:[0-9]{1,5}',
|
|
|
- });
|
|
|
|
|
|
|
+ } as LokiExpression);
|
|
|
expect(parseQuery('\\.java:[0-9]{1,5} {foo="bar"}')).toEqual({
|
|
expect(parseQuery('\\.java:[0-9]{1,5} {foo="bar"}')).toEqual({
|
|
|
query: '{foo="bar"}',
|
|
query: '{foo="bar"}',
|
|
|
regexp: '(?i)\\.java:[0-9]{1,5}',
|
|
regexp: '(?i)\\.java:[0-9]{1,5}',
|
|
|
- });
|
|
|
|
|
|
|
+ } as LokiExpression);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('returns query with filter operands as is', () => {
|
|
|
|
|
+ expect(parseQuery('{foo="bar"} |= "x|y"')).toEqual({
|
|
|
|
|
+ query: '{foo="bar"} |= "x|y"',
|
|
|
|
|
+ regexp: '',
|
|
|
|
|
+ } as LokiExpression);
|
|
|
|
|
+ expect(parseQuery('{foo="bar"} |~ "42"')).toEqual({
|
|
|
|
|
+ query: '{foo="bar"} |~ "42"',
|
|
|
|
|
+ regexp: '',
|
|
|
|
|
+ } as LokiExpression);
|
|
|
|
|
+ });
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+describe('getHighlighterExpressionsFromQuery', () => {
|
|
|
|
|
+ it('returns no expressions for empty query', () => {
|
|
|
|
|
+ expect(getHighlighterExpressionsFromQuery('')).toEqual([]);
|
|
|
|
|
+ });
|
|
|
|
|
+ it('returns a single expressions for legacy query', () => {
|
|
|
|
|
+ expect(getHighlighterExpressionsFromQuery('{} x')).toEqual(['(?i)x']);
|
|
|
|
|
+ expect(getHighlighterExpressionsFromQuery('{foo="bar"} x')).toEqual(['(?i)x']);
|
|
|
|
|
+ });
|
|
|
|
|
+ it('returns an expression for query with filter', () => {
|
|
|
|
|
+ expect(getHighlighterExpressionsFromQuery('{foo="bar"} |= "x"')).toEqual(['x']);
|
|
|
|
|
+ });
|
|
|
|
|
+ it('returns expressions for query with filter chain', () => {
|
|
|
|
|
+ expect(getHighlighterExpressionsFromQuery('{foo="bar"} |= "x" |~ "y"')).toEqual(['x', 'y']);
|
|
|
|
|
+ });
|
|
|
|
|
+ it('returns drops expressions for query with negative filter chain', () => {
|
|
|
|
|
+ expect(getHighlighterExpressionsFromQuery('{foo="bar"} |= "x" != "y"')).toEqual(['x']);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|