import { describe, expect, it } from 'vitest'; import { fmt } from '../src/ui/format'; const stripThin = (s: string) => s.replace(/ /g, ' '); describe('value formatting', () => { it('uses a real minus sign, not a hyphen', () => { expect(fmt.db(-12.3)).toContain('−'); expect(fmt.db(-12.3)).not.toContain('-'); }); it('never renders a negative zero', () => { // A Doppler ratio a hair under 1 must read "0.0 ¢", not "−0.0 ¢". expect(stripThin(fmt.cents(-0.0001))).toBe('0.0 ¢'); expect(stripThin(fmt.cents(0))).toBe('0.0 ¢'); expect(stripThin(fmt.speed(-0.004))).toBe('0.0 m/s'); expect(stripThin(fmt.db(-0.02))).toBe('0.0 dB'); }); it('signs real values', () => { expect(stripThin(fmt.cents(38.2))).toBe('+38.2 ¢'); expect(stripThin(fmt.cents(-38.2))).toBe('−38.2 ¢'); }); it('renders silence as −∞ rather than a huge number', () => { expect(stripThin(fmt.db(-120))).toBe('−∞ dB'); expect(stripThin(fmt.db(-500))).toBe('−∞ dB'); }); it('survives non-finite input', () => { for (const formatter of [fmt.metres, fmt.db, fmt.degrees, fmt.seconds, fmt.ms, fmt.speed]) { expect(formatter(Number.NaN)).toBe('—'); expect(formatter(Number.POSITIVE_INFINITY)).toBe('—'); } expect(fmt.hz(Number.NaN)).toBe('—'); expect(fmt.cents(Number.NaN)).toBe('—'); }); it('switches Hz to kHz with three significant figures', () => { expect(stripThin(fmt.hz(350))).toBe('350 Hz'); expect(stripThin(fmt.hz(1700))).toBe('1.70 kHz'); expect(stripThin(fmt.hz(22050))).toBe('22.1 kHz'); }); it('keeps decimals fixed so numbers do not jitter in width', () => { expect(stripThin(fmt.metres(5))).toBe('5.00 m'); expect(stripThin(fmt.metres(12.345))).toBe('12.35 m'); expect(stripThin(fmt.ratio(1))).toBe('×1.0000'); }); });