From b19336659c6175cbffd72bc3e7baa06868388b68 Mon Sep 17 00:00:00 2001 From: brobert Date: Fri, 17 Oct 2025 14:14:53 +0200 Subject: [PATCH] feat: agregar funciones code, section y bullets y pruebas Co-authored-by: aider (openrouter/openai/gpt-5) --- src/utils/formatting.ts | 12 ++++++++++++ tests/unit/utils/formatting.test.ts | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/unit/utils/formatting.test.ts diff --git a/src/utils/formatting.ts b/src/utils/formatting.ts index c950c2b..5908763 100644 --- a/src/utils/formatting.ts +++ b/src/utils/formatting.ts @@ -30,3 +30,15 @@ export function bold(s: string): string { export function italic(s: string): string { return `_${s}_`; } + +export function code(s: string): string { + return '`' + String(s) + '`'; +} + +export function section(s: string): string { + return `*${String(s).toUpperCase()}*`; +} + +export function bullets(items: string[]): string { + return (items || []).map((i) => `- ${String(i)}`).join('\n'); +} diff --git a/tests/unit/utils/formatting.test.ts b/tests/unit/utils/formatting.test.ts new file mode 100644 index 0000000..4c93395 --- /dev/null +++ b/tests/unit/utils/formatting.test.ts @@ -0,0 +1,19 @@ +import { describe, it, expect } from 'bun:test'; +import { code, section, bullets } from '../../../src/utils/formatting'; + +describe('utils/formatting helpers', () => { + it('code envuelve en backticks', () => { + expect(code('abc')).toBe('`abc`'); + expect(code('')).toBe('``'); + }); + + it('section devuelve mayúsculas en negrita', () => { + expect(section('Comandos básicos')).toBe('*COMANDOS BÁSICOS*'); + expect(section('web')).toBe('*WEB*'); + }); + + it('bullets genera lista con guiones', () => { + expect(bullets(['uno', 'dos'])).toBe('- uno\n- dos'); + expect(bullets([])).toBe(''); + }); +});