syntax.test.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Prism from 'prismjs';
  2. import syntax from './syntax';
  3. describe('Loki syntax', () => {
  4. it('should highlight Loki query correctly', () => {
  5. expect(Prism.highlight('{key="val#ue"}', syntax, 'loki')).toBe(
  6. '<span class="token context-labels"><span class="token punctuation">{</span><span class="token label-key attr-name">key</span>=<span class="token label-value attr-value">"val#ue"</span></span><span class="token punctuation">}</span>'
  7. );
  8. expect(Prism.highlight('{key="#value"}', syntax, 'loki')).toBe(
  9. '<span class="token context-labels"><span class="token punctuation">{</span><span class="token label-key attr-name">key</span>=<span class="token label-value attr-value">"#value"</span></span><span class="token punctuation">}</span>'
  10. );
  11. expect(Prism.highlight('{key="value#"}', syntax, 'loki')).toBe(
  12. '<span class="token context-labels"><span class="token punctuation">{</span><span class="token label-key attr-name">key</span>=<span class="token label-value attr-value">"value#"</span></span><span class="token punctuation">}</span>'
  13. );
  14. expect(Prism.highlight('#test{key="value"}', syntax, 'loki')).toBe(
  15. '<span class="token comment">#test{key="value"}</span>'
  16. );
  17. expect(Prism.highlight('{key="value"}#test', syntax, 'loki')).toBe(
  18. '<span class="token context-labels"><span class="token punctuation">{</span><span class="token label-key attr-name">key</span>=<span class="token label-value attr-value">"value"</span></span><span class="token punctuation">}</span><span class="token comment">#test</span>'
  19. );
  20. expect(Prism.highlight('{key="value"', syntax, 'loki')).toBe(
  21. '<span class="token context-labels"><span class="token punctuation">{</span><span class="token label-key attr-name">key</span>=<span class="token label-value attr-value">"value"</span></span>'
  22. );
  23. expect(Prism.highlight('{Key="value"', syntax, 'loki')).toBe(
  24. '<span class="token context-labels"><span class="token punctuation">{</span><span class="token label-key attr-name">Key</span>=<span class="token label-value attr-value">"value"</span></span>'
  25. );
  26. });
  27. it('should highlight functions in Loki query correctly', () => {
  28. expect(Prism.highlight('rate({key="value"}[5m])', syntax, 'loki')).toContain(
  29. '<span class="token function">rate</span>'
  30. );
  31. expect(Prism.highlight('avg_over_time({key="value"}[5m])', syntax, 'loki')).toContain(
  32. '<span class="token function">avg_over_time</span>'
  33. );
  34. });
  35. it('should highlight operators in Loki query correctly', () => {
  36. expect(Prism.highlight('{key="value"} |= "test"', syntax, 'loki')).toContain(
  37. '<span class="token operator"> |= </span>'
  38. );
  39. expect(Prism.highlight('{key="value"} |~"test"', syntax, 'loki')).toContain(
  40. '<span class="token operator"> |~</span>'
  41. );
  42. });
  43. it('should highlight pipe operations in Loki query correctly', () => {
  44. expect(Prism.highlight('{key="value"} |= "test" | logfmt', syntax, 'loki')).toContain(
  45. '<span class="token pipe-operator operator">|</span> <span class="token pipe-operations keyword">logfmt</span></span>'
  46. );
  47. expect(Prism.highlight('{key="value"} |= "test" | label_format', syntax, 'loki')).toContain(
  48. '<span class="token context-pipe"> <span class="token pipe-operator operator">|</span> <span class="token pipe-operations keyword">label_format</span></span>'
  49. );
  50. });
  51. });