import { describe, expect, it } from 'vitest' import { escapeRawGt, highlightCodeBlock } from '../../../../server/utils/shiki' describe('escapeRawGt', () => { it('should encode > in arrow functions', () => { const input = '=>' const output = escapeRawGt(input) expect(output).toBe('=>') }) it('should encode > in comparison operators', () => { const input = 'x > 5' const output = escapeRawGt(input) expect(output).toBe('x > 5') }) it('should encode multiple > in text content', () => { const input = 'a > b > c' const output = escapeRawGt(input) expect(output).toBe('a > b > c') }) it('should not affect HTML tag structure', () => { const input = 'text' const output = escapeRawGt(input) expect(output).toBe('text') }) it('should not affect attributes containing >', () => { // Attributes with > are already encoded by Shiki, but test anyway const input = 'text' const output = escapeRawGt(input) expect(output).toBe('text') }) it('should handle empty text content', () => { const input = '' const output = escapeRawGt(input) expect(output).toBe('') }) it('should handle text without special characters', () => { const input = 'hello world' const output = escapeRawGt(input) expect(output).toBe('hello world') }) it('should handle nested spans (Shiki output structure)', () => { const input = 'const x = () => 5' const output = escapeRawGt(input) expect(output).toBe( 'const x = () => 5', ) }) it('should handle >= operator', () => { const input = 'x >= 5' const output = escapeRawGt(input) expect(output).toBe('x >= 5') }) it('should handle generic type syntax', () => { const input = 'Array<T>' const output = escapeRawGt(input) // The < is already encoded, the > should be encoded expect(output).toBe('Array<T>') }) }) describe('highlightCodeBlock', () => { it('should highlight TypeScript code', async () => { const code = 'const x = 1' const html = await highlightCodeBlock(code, 'typescript') expect(html).toContain(' in arrow functions', async () => { const code = 'const fn = () => 5' const html = await highlightCodeBlock(code, 'typescript') // The > in => should be encoded expect(html).toContain('=>') expect(html).not.toMatch(/=>(?!&)/) // no raw => (except in >) }) it('should encode > in generic types', async () => { const code = 'const x: Array = []' const html = await highlightCodeBlock(code, 'typescript') // Should have encoded > expect(html).toContain('>') }) it('should fall back to plain code for unknown languages', async () => { const code = 'some random code > with special < chars' const html = await highlightCodeBlock(code, 'unknownlang123') expect(html).toContain('>') expect(html).toContain('<') expect(html).toContain('language-unknownlang123') }) it('should escape special characters in fallback', async () => { const code = '' const html = await highlightCodeBlock(code, 'unknownlang123') expect(html).toContain('<script>') expect(html).not.toContain('