import Prism from 'prismjs';
import syntax from './syntax';
describe('Loki syntax', () => {
it('should highlight Loki query correctly', () => {
expect(Prism.highlight('{key="val#ue"}', syntax, 'loki')).toBe(
'{key="val#ue"}'
);
expect(Prism.highlight('{key="#value"}', syntax, 'loki')).toBe(
'{key="#value"}'
);
expect(Prism.highlight('{key="value#"}', syntax, 'loki')).toBe(
'{key="value#"}'
);
expect(Prism.highlight('#test{key="value"}', syntax, 'loki')).toBe(
''
);
expect(Prism.highlight('{key="value"}#test', syntax, 'loki')).toBe(
'{key="value"}'
);
expect(Prism.highlight('{key="value"', syntax, 'loki')).toBe(
'{key="value"'
);
expect(Prism.highlight('{Key="value"', syntax, 'loki')).toBe(
'{Key="value"'
);
});
it('should highlight functions in Loki query correctly', () => {
expect(Prism.highlight('rate({key="value"}[5m])', syntax, 'loki')).toContain(
'rate'
);
expect(Prism.highlight('avg_over_time({key="value"}[5m])', syntax, 'loki')).toContain(
'avg_over_time'
);
});
it('should highlight operators in Loki query correctly', () => {
expect(Prism.highlight('{key="value"} |= "test"', syntax, 'loki')).toContain(
' |= '
);
expect(Prism.highlight('{key="value"} |~"test"', syntax, 'loki')).toContain(
' |~'
);
});
it('should highlight pipe operations in Loki query correctly', () => {
expect(Prism.highlight('{key="value"} |= "test" | logfmt', syntax, 'loki')).toContain(
'| logfmt'
);
expect(Prism.highlight('{key="value"} |= "test" | label_format', syntax, 'loki')).toContain(
' | label_format'
);
});
});