update
This commit is contained in:
60
test/highlight.test.ts
Normal file
60
test/highlight.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { HL } from '../src/renderer/src/highlight'
|
||||
|
||||
describe('HL.ext', () => {
|
||||
it('extracts a normal extension', () => {
|
||||
expect(HL.ext('src/a/b.php')).toBe('php')
|
||||
expect(HL.ext('x.TSX')).toBe('tsx')
|
||||
})
|
||||
it('treats dotfiles like .env specially', () => {
|
||||
expect(HL.ext('.env')).toBe('env')
|
||||
expect(HL.ext('config/.env.local')).toBe('env')
|
||||
})
|
||||
it('returns empty for no extension', () => {
|
||||
expect(HL.ext('Makefile')).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('HL.langFor / langLabel', () => {
|
||||
it('maps known extensions to Prism languages', () => {
|
||||
expect(HL.langFor('a.php')).toBe('php')
|
||||
expect(HL.langFor('a.ts')).toBe('typescript')
|
||||
expect(HL.langFor('a.py')).toBe('python')
|
||||
expect(HL.langFor('a.unknownext')).toBeNull()
|
||||
})
|
||||
it('produces human labels', () => {
|
||||
expect(HL.langLabel('a.php')).toBe('PHP')
|
||||
expect(HL.langLabel('a.tsx')).toBe('TypeScript')
|
||||
expect(HL.langLabel('Makefile')).toBe('Plain Text')
|
||||
})
|
||||
})
|
||||
|
||||
describe('HL.iconFor', () => {
|
||||
it('uses name-specific icons', () => {
|
||||
expect(HL.iconFor('composer.json').t).toBe('co')
|
||||
expect(HL.iconFor('package.json').t).toBe('pk')
|
||||
})
|
||||
it('falls back to extension icons', () => {
|
||||
expect(HL.iconFor('x.php').c).toBe('#a78bdb')
|
||||
})
|
||||
it('falls back to first two letters for unknown types', () => {
|
||||
expect(HL.iconFor('weird.zzz').t).toBe('we')
|
||||
})
|
||||
})
|
||||
|
||||
describe('HL.escapeHtml', () => {
|
||||
it('escapes html-significant characters', () => {
|
||||
expect(HL.escapeHtml('<a> & </a>')).toBe('<a> & </a>')
|
||||
})
|
||||
})
|
||||
|
||||
describe('HL.hlText (Prism)', () => {
|
||||
it('wraps php keywords in token spans (markup-templating loaded first)', () => {
|
||||
const out = HL.hlText('<?php class A {}', 'php')
|
||||
expect(out).toContain('token')
|
||||
expect(out).toContain('class')
|
||||
})
|
||||
it('escapes when no grammar is available', () => {
|
||||
expect(HL.hlText('<x>', null)).toBe('<x>')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user