hermes-agent/ui-tui/src/__tests__/syntax.test.ts
brooklyn! 6b09df39be
fix(tui): restore macOS copy behavior and theme polish (#17131)
This PR groups the TUI fixes that restore macOS Terminal usability and clean up the theme/composer regressions:

- copy transcript selections on macOS drag-release so Terminal.app users can copy while mouse tracking is enabled
- copy composer selections on macOS drag-release; composer selection is internal to TextInput and does not use the global Ink selection bus
- keep IDE Cmd+C forwarding setup macOS-only, and make keybinding conflict checks respect simple when-clause overlap/negation
- force truecolor before chalk initializes (unless NO_COLOR / FORCE_COLOR / HERMES_TUI_TRUECOLOR opt-outs apply) so the default banner keeps its gold/amber/bronze gradient in Terminal.app
- move TUI surfaces onto semantic theme tokens and preserve skin prompt symbols as bare tokens with renderer-owned spacing
- render focused placeholders as dim hint text in TTY mode instead of inverse/selected-looking synthetic cursor text
2026-04-28 18:47:14 -05:00

45 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { highlightLine, isHighlightable } from '../lib/syntax.js'
import { DEFAULT_THEME } from '../theme.js'
const t = DEFAULT_THEME
describe('syntax highlighter', () => {
it('recognizes supported langs and aliases', () => {
expect(isHighlightable('ts')).toBe(true)
expect(isHighlightable('js')).toBe(true)
expect(isHighlightable('python')).toBe(true)
expect(isHighlightable('rs')).toBe(true)
expect(isHighlightable('bash')).toBe(true)
expect(isHighlightable('whatever')).toBe(false)
expect(isHighlightable('')).toBe(false)
})
it('paints a whole-line comment dim', () => {
const tokens = highlightLine('// hello', 'ts', t)
expect(tokens).toEqual([[t.color.muted, '// hello']])
})
it('paints keywords, strings, and numbers in a ts line', () => {
const tokens = highlightLine(`const x = 'hi' + 42`, 'ts', t)
const colors = tokens.map(tok => tok[0])
expect(colors).toContain(t.color.border) // const
expect(colors).toContain(t.color.accent) // 'hi'
expect(colors).toContain(t.color.text) // 42
})
it('falls through unchanged for unknown langs', () => {
const tokens = highlightLine(`const x = 1`, 'zzz', t)
expect(tokens).toEqual([['', 'const x = 1']])
})
it('treats `#` as a python comment, not a selector', () => {
const tokens = highlightLine('# comment', 'py', t)
expect(tokens).toEqual([[t.color.muted, '# comment']])
})
})