read text aloud
This commit is contained in:
@@ -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"),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import Testing
|
||||
|
||||
@Suite struct MarkdownSpeechTests {
|
||||
private func speech(_ markdown: String) -> String {
|
||||
MarkdownSpeech.plainText(MarkdownParser.parse(markdown))
|
||||
}
|
||||
|
||||
@Test func eachBlockIsItsOwnSentence() {
|
||||
#expect(speech("# Title\n\nFirst paragraph\n\nSecond one!") == "Title.\nFirst paragraph.\nSecond one!")
|
||||
}
|
||||
|
||||
@Test func inlineMarkupIsStrippedAndLinksKeepTheirText() {
|
||||
#expect(speech("Some **bold**, *soft*, ~~old~~ and `code` in [the docs](https://x.com).")
|
||||
== "Some bold, soft, old and code in the docs.")
|
||||
}
|
||||
|
||||
@Test func listItemsQuotesAndTableRowsAreRead() {
|
||||
#expect(speech("- one\n- two:\n\n> quoted") == "one.\ntwo:\nquoted.")
|
||||
#expect(speech("| Name | Role |\n|---|---|\n| Ann | dev |") == "Name, Role.\nAnn, dev.")
|
||||
}
|
||||
|
||||
@Test func codeBlocksAndRulesAreSkipped() {
|
||||
#expect(speech("Before\n\n```php\necho 1;\n```\n\n---\n\nAfter") == "Before.\nAfter.")
|
||||
#expect(speech("```\nonly code\n```").isEmpty)
|
||||
}
|
||||
|
||||
@Test func aDollarSignIsSpokenAsDollar() {
|
||||
#expect(MarkdownSpeech.spoken("echo $user") == "echo dollar user")
|
||||
#expect(MarkdownSpeech.spoken("$ x") == "dollar x")
|
||||
#expect(MarkdownSpeech.spoken("a$$") == "a dollar dollar")
|
||||
}
|
||||
|
||||
@Test func aDollarBeforeADigitAndTextWithoutDollarStay() {
|
||||
#expect(MarkdownSpeech.spoken("It costs $5.") == "It costs $5.")
|
||||
#expect(MarkdownSpeech.spoken("No money here.") == "No money here.")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user