39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { expandSnippetVariables } from '../../src/utils/snippetVariables'
|
|
import { applyKeywordHighlights, DEFAULT_KEYWORD_HIGHLIGHT_RULES } from '../../src/utils/keywordHighlight'
|
|
|
|
describe('expandSnippetVariables', () => {
|
|
it('replaces known placeholders', () => {
|
|
const out = expandSnippetVariables('ssh {{username}}@{{host}}:{{port}}', {
|
|
username: 'root',
|
|
host: '10.0.0.1',
|
|
port: 22,
|
|
})
|
|
expect(out).toBe('ssh root@10.0.0.1:22')
|
|
})
|
|
|
|
it('uses default when missing', () => {
|
|
const out = expandSnippetVariables('cd {{path:/tmp}}', {})
|
|
expect(out).toBe('cd /tmp')
|
|
})
|
|
|
|
it('keeps unknown placeholders without default', () => {
|
|
const out = expandSnippetVariables('echo {{unknown}}', {})
|
|
expect(out).toBe('echo {{unknown}}')
|
|
})
|
|
})
|
|
|
|
describe('applyKeywordHighlights', () => {
|
|
it('highlights error keywords', () => {
|
|
const out = applyKeywordHighlights('FATAL error happened', DEFAULT_KEYWORD_HIGHLIGHT_RULES)
|
|
expect(out).toContain('\x1b[')
|
|
expect(out).toContain('FATAL')
|
|
})
|
|
|
|
it('returns original when disabled rules only', () => {
|
|
const rules = DEFAULT_KEYWORD_HIGHLIGHT_RULES.map((r) => ({ ...r, enabled: false }))
|
|
const text = 'no highlight'
|
|
expect(applyKeywordHighlights(text, rules)).toBe(text)
|
|
})
|
|
})
|