import { describe, test, expect } from 'vitest'; import { formatHtml } from './format-html'; describe('formatHtml', () => { test('indents nested block elements two spaces per level', () => { expect(formatHtml('

hi

')).toBe( '
\n
\n

hi

\n
\n
', ); }); test('leaves inline tags on the same line as their text', () => { expect(formatHtml('

hello world now

')).toBe( '

hello world now

', ); }); test('void elements do not open an indent level', () => { expect(formatHtml('

x

')).toBe( '
\n \n
\n

x

\n
', ); }); test('preserves
 contents verbatim', () => {
    const src = '
  keep\n   this
'; expect(formatHtml(src)).toBe('
\n
  keep\n   this
\n
'); }); test('is idempotent', () => { const once = formatHtml('

hi

'); expect(formatHtml(once)).toBe(once); }); test('empty and whitespace-only input round-trip to an empty string', () => { expect(formatHtml('')).toBe(''); expect(formatHtml(' \n ')).toBe(''); }); test('unbalanced markup never produces negative indent', () => { expect(formatHtml('

x

')).toBe('\n

x

'); }); }); // Regression coverage from code review: only
 was originally exempted
// from the naive '<'/'>' tag-boundary scan, which let a '>' inside a quoted
// attribute value corrupt output, and let '<'/'>' inside 
'; expect(formatHtml(src)).toBe( '
\n \n
\n
\n \n
', ); }); test('a CSS child combinator inside '; expect(formatHtml(src)).toBe( '
\n \n
', ); }); test('is idempotent across a quoted ">" attribute and
'; const scripted = formatHtml(scriptSrc); expect(formatHtml(scripted)).toBe(scripted); }); test('an unclosed
 is swallowed verbatim to the end of the document', () => {
    expect(formatHtml('
no closing tag here')).toBe(
      '
\n
no closing tag here',
    );
  });
});