//
// Copyright 2025 DXOS.org
//
import { describe, test } from 'vitest';
import { trim } from '@dxos/util';
import { xmlElementLength } from './typewriter.ts';
describe('typewriter', () => {
test('xmlElementLength handles hyphenated custom element names', ({ expect }) => {
const inner = 'Hello';
const el = `${inner}`;
expect(xmlElementLength(el)).toBe(el.length);
});
test('xmlElementLength handle multi-line tags', ({ expect }) => {
const el = trim`
Line 1
Line 2
`;
expect(xmlElementLength(el)).toBe(el.length);
});
test('xmlElementLength handles simple tag names', ({ expect }) => {
const el = 'Hi';
expect(xmlElementLength(el)).toBe(el.length);
});
test('xmlElementLength returns 0 until closing tag is complete', ({ expect }) => {
expect(xmlElementLength('x')).toBe(0);
});
test('xmlElementLength handles tags with blank lines in content', ({ expect }) => {
const el = trim`
The user is asking me to think deeply about what markdown is.
But given the context of our conversation - we've been trying to scrape slab data from a website - I think they might be hinting at something specific.
`;
expect(xmlElementLength(el)).toBe(el.length);
});
test('xmlElementLength handles tags with multiple blank lines', ({ expect }) => {
const el = trim`
First paragraph.
Second paragraph after two blank lines.
`;
expect(xmlElementLength(el)).toBe(el.length);
});
test('xmlElementLength handles tags with only blank lines', ({ expect }) => {
const el = '\n\n\n';
expect(xmlElementLength(el)).toBe(el.length);
});
});