36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import { speechTextFromMarkdown, splitSpeechText } from '../src/speech.ts'
|
|
|
|
test('markdown is converted to natural speech without fenced code or URLs', () => {
|
|
const markdown = `# Résultat
|
|
|
|
Voici **la réponse** avec [la documentation](https://example.com/docs) et \`npm test\`.
|
|
|
|
\`\`\`ts
|
|
const secret = 'not read aloud'
|
|
\`\`\`
|
|
|
|
- Premier point
|
|
- Deuxième point`
|
|
|
|
const spoken = speechTextFromMarkdown(markdown)
|
|
|
|
assert.match(spoken, /Résultat/)
|
|
assert.match(spoken, /la réponse/)
|
|
assert.match(spoken, /la documentation/)
|
|
assert.match(spoken, /npm test/)
|
|
assert.match(spoken, /Bloc de code omis/)
|
|
assert.doesNotMatch(spoken, /https|secret|\*\*|```/)
|
|
})
|
|
|
|
test('long speech is split into short non-empty chunks without losing text', () => {
|
|
const text = `${'Une phrase assez longue. '.repeat(18)}Dernière phrase.`
|
|
const chunks = splitSpeechText(text, 180)
|
|
|
|
assert.ok(chunks.length > 1)
|
|
assert.ok(chunks.every(chunk => chunk.length > 0 && chunk.length <= 180))
|
|
assert.equal(chunks.join(' '), text.replace(/\s+/g, ' ').trim())
|
|
})
|