Branchwell

Inkspring / app · inkspring.ai / native-mac / Tests / InkspringTests / ProofreadingTests.swift

Raw 2.3 KB on 8f75dd7d901e2186ca9d9e1cf2f061105c02ae42
1import Testing
2@testable import Inkspring
3
4@Test @MainActor func proofreadingKeepsFormattingAndRejectsUnmatchedEdits() async throws {
5 let original = ProofreadDocument(title: "A newletter", body: """
6 👋 We has a plan. [Read it](https://example.com/has) or use `we has`.
7 Repeated phrase. Repeated phrase.
8
9 ```text
10 We has a template.
11 ```
12 """)
13 let review = try await ProofreadReview.check(original, chunkSize: 500) { excerpt in
14 if excerpt == original.title {
15 return [.init(original: "newletter", replacement: "newsletter", reason: "Spelling")]
16 }
17 return [
18 .init(original: "We has a plan.", replacement: "We have a plan.", reason: "Subject–verb agreement"),
19 .init(original: "has a plan", replacement: "have a plan", reason: "Overlapping correction"),
20 .init(original: "we has", replacement: "we have", reason: "Inline code"),
21 .init(original: "We has a template.", replacement: "We have a template.", reason: "Fenced code"),
22 .init(original: "https://example.com/has", replacement: "https://example.com/have", reason: "URL"),
23 .init(original: "Repeated phrase.", replacement: "Repeated sentence.", reason: "Ambiguous excerpt"),
24 .init(original: "Missing phrase", replacement: "No match", reason: "Unmatched excerpt"),
25 ]
26 }
27 #expect(review.original == original)
28 #expect(review.corrected.title == "A newsletter")
29 #expect(review.corrected.body == original.body.replacingOccurrences(of: "We has a plan.", with: "We have a plan."))
30 #expect(review.edits.count == 2)
31 #expect(review.skipped == 6)
32}
33
34@Test @MainActor func proofreadingChecksTheEndOfLongTextAndPreservesSeparation() async throws {
35 let beginning = String(repeating: "We work.\n\n", count: 90)
36 let original = ProofreadDocument(body: beginning + "We workd today.")
37 var checked = ""
38 let review = try await ProofreadReview.check(original, chunkSize: 80) { excerpt in
39 #expect(excerpt.count <= 80)
40 checked += excerpt
41 if excerpt.contains("workd") {
42 return [.init(original: "workd", replacement: "worked", reason: "Spelling")]
43 }
44 return []
45 }
46 #expect(checked == original.body)
47 #expect(review.corrected.body == beginning + "We worked today.")
48}