import { describe, it, expect } from 'vitest';
import { splitByMarkers } from './transcriptionMarkers';

describe('splitByMarkers', () => {
	it('should return single text segment for plain text', () => {
		const result = splitByMarkers('Hello world');
		expect(result).toEqual([{ type: 'text', text: 'Hello world' }]);
	});

	it('should split [unleserlich] into a marker segment', () => {
		const result = splitByMarkers('before [unleserlich] after');
		expect(result).toEqual([
			{ type: 'text', text: 'before ' },
			{ type: 'marker', text: '[unleserlich]' },
			{ type: 'text', text: ' after' }
		]);
	});

	it('should split [...] into a marker segment', () => {
		const result = splitByMarkers('some text [...] more text');
		expect(result).toEqual([
			{ type: 'text', text: 'some text ' },
			{ type: 'marker', text: '[...]' },
			{ type: 'text', text: ' more text' }
		]);
	});

	it('should handle multiple markers in one string', () => {
		const result = splitByMarkers('[unleserlich] middle [...] end');
		expect(result).toEqual([
			{ type: 'marker', text: '[unleserlich]' },
			{ type: 'text', text: ' middle ' },
			{ type: 'marker', text: '[...]' },
			{ type: 'text', text: ' end' }
		]);
	});

	it('should handle text that is only a marker', () => {
		const result = splitByMarkers('[unleserlich]');
		expect(result).toEqual([{ type: 'marker', text: '[unleserlich]' }]);
	});

	it('should handle empty string', () => {
		const result = splitByMarkers('');
		expect(result).toEqual([]);
	});

	it('should not match other bracket markers', () => {
		const result = splitByMarkers('text [Seitenumbruch] more');
		expect(result).toEqual([{ type: 'text', text: 'text [Seitenumbruch] more' }]);
	});

	it('should handle adjacent markers', () => {
		const result = splitByMarkers('[unleserlich][...]');
		expect(result).toEqual([
			{ type: 'marker', text: '[unleserlich]' },
			{ type: 'marker', text: '[...]' }
		]);
	});
});
