M2: TranslationAdapter/AdapterRegistry with documented Hy-MT3 prompts and publisher sampling; all 102 languages with BCP-47 variants, RTL and dense-script flags; normalisation, NLLanguage detection, content classification and exact-join script-aware chunking; protected-token scanning and output validation; prompt policy with one documented fallback; shared TranslationPipeline with Core error mapping. The CLI now reports sourceLanguage and warning codes. M3: pure DoubleCopyDetector, 120 ms PasteboardWatcher with 750 ms own-write suppression, SystemPasteboard snapshot/restore and markers, CapturePolicy for the 4000/2000 limits, ServicesProvider and the menu-bar action. T3.5 (10-app manual matrix) remains intentionally open. Docs: ARCHITECTURE, TRANSLATION_OUTPUT, HYMT3_MODEL (§7 spike), SELECTION_AND_CLIPBOARD, PROGRESS; ADR-016 superseded by ADR-017/018. Verified: make verify green (format, strict lint, scripts, privacy, Debug+Release signatures, package tests); live 7B CLI en→de/de→en/Markdown/JSON/placeholders; empty input exits 2 and unreachable exits 3.
62 lines
2.4 KiB
Swift
62 lines
2.4 KiB
Swift
import SprachmittlerText
|
|
import Testing
|
|
@testable import SprachmittlerEngines
|
|
|
|
@Suite("Prompt policy")
|
|
struct PromptPolicyTests {
|
|
private let policy = PromptPolicy()
|
|
private let token = ProtectedToken(kind: .url, value: "https://example.com")
|
|
|
|
@Test func v1StartsWithDefaultForEveryContentClass() {
|
|
for content in ContentClass.allCases {
|
|
#expect(policy.initialPrompt(for: content) == .defaultTranslation)
|
|
}
|
|
}
|
|
|
|
@Test func structuredContentUsesStructuredData1AfterALostToken() {
|
|
#expect(policy.retryPrompt(for: .json, lostToken: token) == .structuredData1(format: .json))
|
|
#expect(policy.retryPrompt(for: .html, lostToken: token) == .structuredData1(format: .html))
|
|
#expect(policy.retryPrompt(for: .markdown, lostToken: token) == .structuredData1(format: .markdown))
|
|
}
|
|
|
|
@Test func plainAndDelimitedTextUseDelimitersAfterALostToken() {
|
|
#expect(policy.retryPrompt(for: .plain, lostToken: token) == .delimiters)
|
|
#expect(policy.retryPrompt(for: .delimited, lostToken: token) == .delimiters)
|
|
#expect(policy.retryPrompt(for: .code, lostToken: token) == .delimiters)
|
|
}
|
|
}
|
|
|
|
@Suite("Repetition and numbers")
|
|
struct RepetitionAndNumberTests {
|
|
@Test func detectsARepeatedLine() {
|
|
let text = Array(repeating: "This is a repeated line.", count: 6).joined(separator: "\n")
|
|
#expect(RepetitionDetector.detectsLoop(in: text))
|
|
}
|
|
|
|
@Test func doesNotFlagOrdinaryText() {
|
|
#expect(!RepetitionDetector.detectsLoop(in: "This is an ordinary translation with no loop."))
|
|
}
|
|
|
|
@Test func detectsARepeatedWindow() {
|
|
let window = String(repeating: "a", count: 64)
|
|
#expect(RepetitionDetector.detectsLoop(in: String(repeating: window, count: 8)))
|
|
}
|
|
|
|
@Test func incrementalDetectorFiresWhileStreaming() {
|
|
var detector = RepetitionDetector()
|
|
var fired = false
|
|
for _ in 0 ..< 6 {
|
|
fired = detector.append("This is a repeated line.\n")
|
|
}
|
|
#expect(fired)
|
|
}
|
|
|
|
@Test func numericNormalisationTreatsLocaleSeparatorsAsEqual() {
|
|
#expect(NumericTokenNormalizer.normalize("1.5") == "1.5")
|
|
#expect(NumericTokenNormalizer.normalize("1,5") == "1.5")
|
|
#expect(NumericTokenNormalizer.normalize("1 000") == "1000")
|
|
#expect(NumericTokenNormalizer.normalize("1,234.56") == "1234.56")
|
|
#expect(NumericTokenNormalizer.normalize("1.234,56") == "1234.56")
|
|
}
|
|
}
|