read text aloud

This commit is contained in:
2026-10-23 09:40:20 +02:00
parent 281f5465a6
commit 92b90c0e13
20 changed files with 471 additions and 18 deletions
@@ -10,10 +10,15 @@ import Testing
}
@Test func copyAppearsOnlyWithASelection() {
#expect(labels(.terminal(.agent, hasSelection: true)) == ["Copy", "Paste"])
#expect(labels(.terminal(.agent, hasSelection: true)) == ["Copy", "Paste", "Wait what?"])
#expect(labels(.terminal(.shell, hasSelection: false)) == ["Paste"])
}
@Test func waitWhatAppearsOnlyForASelectionInTheAgentPane() {
#expect(!labels(.terminal(.agent, hasSelection: false)).contains("Wait what?"))
#expect(!labels(.terminal(.shell, hasSelection: true)).contains("Wait what?"))
}
@Test func theActionsNameTheirPane() {
#expect(ContextActions.entries(for: .terminal(.shell, hasSelection: true)) == [
.action(.copyTerminalSelection(.shell), label: "Copy"),
@@ -83,3 +88,58 @@ import Testing
#expect(!hasBouwen(.file(path: "ontwikkelingen/a")))
}
}
@Suite struct ReadAloudContextMenuTests {
private func readAloud(_ target: ContextTarget) -> [ContextMenuEntry] {
ContextActions.entries(for: target).filter { entry in
switch entry {
case .action(.readAloudFile, _), .action(.readAloudText, _): true
default: false
}
}
}
@Test func aMarkdownFileCanBeReadAloud() {
let entries = ContextActions.entries(for: .file(path: "docs/guide.md"))
#expect(Array(entries[4...6]) == [
.separator,
.action(.readAloudFile("docs/guide.md"), label: "Read aloud"),
.separator,
])
#expect(readAloud(.gitRow(path: "README.md", staged: true)) == [.action(.readAloudFile("README.md"), label: "Read aloud")])
}
@Test func otherFilesCannot() {
#expect(readAloud(.file(path: "src/app.php")).isEmpty)
#expect(readAloud(.gitRow(path: "src/app.php", staged: false)).isEmpty)
#expect(readAloud(.directory(path: "docs")).isEmpty)
}
@Test func aSelectionCanBeReadAloudAfterCopyReference() {
let reference = AgentReference(path: "src/a.php", startLine: 3, endLine: 4)
#expect(ContextActions.entries(for: .editor(reference: reference, code: "$a = 1;", showDiffLine: 3)) == [
.action(.passOnReference("src/a.php:3-4", code: "$a = 1;"), label: "Pass on selection"),
.action(.copyReference("src/a.php:3-4"), label: "Copy reference"),
.separator,
.action(.readAloudText("$a = 1;"), label: "Read aloud selection"),
.separator,
.action(.showDiff("src/a.php", line: 3), label: "Show diff"),
])
}
@Test func noSelectionNoReadAloud() {
let reference = AgentReference(path: "README.md", startLine: 1)
#expect(readAloud(.editor(reference: reference, code: nil)).isEmpty)
#expect(readAloud(.editor(reference: reference, code: "")).isEmpty)
}
@Test func selectedMarkdownIsReadAsProse() {
let reference = AgentReference(path: "README.md", startLine: 1)
#expect(readAloud(.editor(reference: reference, code: "## Setup\nRun **this**")) == [
.action(.readAloudText("Setup.\nRun this."), label: "Read aloud selection"),
])
#expect(readAloud(.editor(reference: reference, code: "```\nls\n```")) == [
.action(.readAloudText("```\nls\n```"), label: "Read aloud selection"),
])
}
}