Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

test: split spoken formatting coverage

altic-dev46dd7c84a5ba
diff --git a/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift b/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift
index 5481da78..2a2ffe14 100644
--- a/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift
+++ b/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift
@@ -601,195 +601,6 @@ final class DictationE2ETests: XCTestCase {
}
}
- func testSpokenFormattingActionsUseSharedPrefix() {
- self.withRestoredDefaults(keys: self.punctuationFormattingDefaultsKeys) {
- let settings = SettingsStore.shared
- UserDefaults.standard.set(true, forKey: self.autoConvertPunctuationEnabledKey)
- settings.punctuationDictionaryPrefix = "literal"
- settings.spokenFormattingActionRules = SettingsStore.defaultSpokenFormattingActionRules
-
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First literal next line second"),
- "First\nsecond"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First literal next paragraph second"),
- "First\n\nsecond"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("one literal tab two"),
- "one\ttwo"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("one literal space two"),
- "one two"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First next line second"),
- "First next line second"
- )
- }
- }
-
- func testSpokenFormattingActionsRemoveAdjacentGeneratedPeriodsOnly() {
- self.withRestoredDefaults(keys: self.punctuationFormattingDefaultsKeys) {
- let settings = SettingsStore.shared
- UserDefaults.standard.set(true, forKey: self.autoConvertPunctuationEnabledKey)
- settings.punctuationDictionaryPrefix = "literal"
- settings.spokenFormattingActionRules = SettingsStore.defaultSpokenFormattingActionRules
-
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First. literal new line. Second"),
- "First\nSecond"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First. literal new paragraph. Second"),
- "First\n\nSecond"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("one. literal tab. two"),
- "one\ttwo"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("one. literal space. two"),
- "one two"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First literal period literal new line Second"),
- "First.\nSecond"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First literal new line, Second"),
- "First\nSecond"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First literal new paragraph, Second"),
- "First\n\nSecond"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First literal new line literal comma Second"),
- "First\n, Second"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("one literal tab, two"),
- "one\t, two"
- )
- }
- }
-
- func testSpokenFormattingActionsCanBeCustomizedAndUnset() {
- self.withRestoredDefaults(keys: self.punctuationFormattingDefaultsKeys) {
- let settings = SettingsStore.shared
- UserDefaults.standard.set(true, forKey: self.autoConvertPunctuationEnabledKey)
- settings.spokenFormattingActionRules = [
- SettingsStore.SpokenFormattingActionRule(
- action: .newLine,
- aliases: ["drop down"]
- ),
- SettingsStore.SpokenFormattingActionRule(
- action: .tab,
- aliases: [],
- isEnabled: true
- ),
- SettingsStore.SpokenFormattingActionRule(
- action: .space,
- aliases: ["little gap"],
- isEnabled: false
- ),
- ]
-
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("First literal drop down second"),
- "First\nsecond"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("literal tab"),
- "literal tab"
- )
- XCTAssertEqual(
- ASRService.applySpokenPunctuationFormatting("literal little gap"),
- "literal little gap"
- )
- }
- }
-
- func testSpokenFormattingActionAliasesRejectPunctuationAndActionConflicts() {
- self.withRestoredDefaults(keys: self.punctuationFormattingDefaultsKeys) {
- let settings = SettingsStore.shared
- settings.spokenFormattingActionRules = [
- SettingsStore.SpokenFormattingActionRule(
- action: .newLine,
- aliases: ["comma", "shared action", "drop down"]
- ),
- SettingsStore.SpokenFormattingActionRule(
- action: .newParagraph,
- aliases: ["shared action", "paragraph break"]
- ),
- ]
-
- let rules = settings.spokenFormattingActionRules
- XCTAssertEqual(rules.first { $0.action == .newLine }?.aliases, ["shared action", "drop down"])
- XCTAssertEqual(rules.first { $0.action == .newParagraph }?.aliases, ["paragraph break"])
-
- UserDefaults.standard.set(true, forKey: self.autoConvertPunctuationEnabledKey)
- XCTAssertEqual(ASRService.applySpokenPunctuationFormatting("literal comma"), ",")
- XCTAssertEqual(ASRService.applySpokenPunctuationFormatting("literal shared action"), "\n")
- }
- }
-
- func testSpokenFormattingActionRulesRoundTripAndLegacyBackupsPreserveCurrentRules() async throws {
- let defaults = UserDefaults.standard
- let originalValue = defaults.object(forKey: self.spokenFormattingActionRulesKey)
- defer {
- if let originalValue {
- defaults.set(originalValue, forKey: self.spokenFormattingActionRulesKey)
- } else {
- defaults.removeObject(forKey: self.spokenFormattingActionRulesKey)
- }
- }
-
- let settings = SettingsStore.shared
- let backedUpRules = [
- SettingsStore.SpokenFormattingActionRule(
- action: .newLine,
- aliases: ["line break"]
- ),
- SettingsStore.SpokenFormattingActionRule(
- action: .tab,
- aliases: ["indent"],
- isEnabled: false
- ),
- ]
- settings.spokenFormattingActionRules = backedUpRules
-
- let document = await BackupService.shared.makeBackupDocument()
- let encoded = try BackupService.shared.encode(document)
- let decoded = try BackupService.shared.decode(encoded)
- XCTAssertEqual(decoded.settings.spokenFormattingActionRules, settings.spokenFormattingActionRules)
-
- settings.spokenFormattingActionRules = SettingsStore.defaultSpokenFormattingActionRules
- settings.restore(from: decoded.settings)
- XCTAssertEqual(settings.spokenFormattingActionRules, decoded.settings.spokenFormattingActionRules)
-
- var root = try XCTUnwrap(JSONSerialization.jsonObject(with: encoded) as? [String: Any])
- var encodedSettings = try XCTUnwrap(root["settings"] as? [String: Any])
- encodedSettings.removeValue(forKey: "spokenFormattingActionRules")
- root["settings"] = encodedSettings
- let legacyBackup = try BackupService.shared.decode(JSONSerialization.data(withJSONObject: root))
- XCTAssertNil(legacyBackup.settings.spokenFormattingActionRules)
-
- let rulesBeforeLegacyRestore = [
- SettingsStore.SpokenFormattingActionRule(
- action: .newParagraph,
- aliases: ["keep this paragraph"]
- ),
- ]
- settings.spokenFormattingActionRules = rulesBeforeLegacyRestore
- let normalizedRulesBeforeLegacyRestore = settings.spokenFormattingActionRules
- settings.restore(from: legacyBackup.settings)
- XCTAssertEqual(settings.spokenFormattingActionRules, normalizedRulesBeforeLegacyRestore)
- }
-
func testTerminalLiteralAutocompleteSpacingLeavesNonAutocompleteTextAlone() {
XCTAssertEqual(
ASRService.applyTerminalLiteralAutocompleteSpacing(
@@ -2524,6 +2335,197 @@ final class DictationE2ETests: XCTestCase {
}
}
+extension DictationE2ETests {
+ func testSpokenFormattingActionsUseSharedPrefix() {
+ self.withRestoredDefaults(keys: self.punctuationFormattingDefaultsKeys) {
+ let settings = SettingsStore.shared
+ UserDefaults.standard.set(true, forKey: self.autoConvertPunctuationEnabledKey)
+ settings.punctuationDictionaryPrefix = "literal"
+ settings.spokenFormattingActionRules = SettingsStore.defaultSpokenFormattingActionRules
+
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First literal next line second"),
+ "First\nsecond"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First literal next paragraph second"),
+ "First\n\nsecond"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("one literal tab two"),
+ "one\ttwo"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("one literal space two"),
+ "one two"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First next line second"),
+ "First next line second"
+ )
+ }
+ }
+
+ func testSpokenFormattingActionsRemoveAdjacentGeneratedPeriodsOnly() {
+ self.withRestoredDefaults(keys: self.punctuationFormattingDefaultsKeys) {
+ let settings = SettingsStore.shared
+ UserDefaults.standard.set(true, forKey: self.autoConvertPunctuationEnabledKey)
+ settings.punctuationDictionaryPrefix = "literal"
+ settings.spokenFormattingActionRules = SettingsStore.defaultSpokenFormattingActionRules
+
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First. literal new line. Second"),
+ "First\nSecond"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First. literal new paragraph. Second"),
+ "First\n\nSecond"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("one. literal tab. two"),
+ "one\ttwo"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("one. literal space. two"),
+ "one two"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First literal period literal new line Second"),
+ "First.\nSecond"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First literal new line, Second"),
+ "First\nSecond"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First literal new paragraph, Second"),
+ "First\n\nSecond"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First literal new line literal comma Second"),
+ "First\n, Second"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("one literal tab, two"),
+ "one\t, two"
+ )
+ }
+ }
+
+ func testSpokenFormattingActionsCanBeCustomizedAndUnset() {
+ self.withRestoredDefaults(keys: self.punctuationFormattingDefaultsKeys) {
+ let settings = SettingsStore.shared
+ UserDefaults.standard.set(true, forKey: self.autoConvertPunctuationEnabledKey)
+ settings.spokenFormattingActionRules = [
+ SettingsStore.SpokenFormattingActionRule(
+ action: .newLine,
+ aliases: ["drop down"]
+ ),
+ SettingsStore.SpokenFormattingActionRule(
+ action: .tab,
+ aliases: [],
+ isEnabled: true
+ ),
+ SettingsStore.SpokenFormattingActionRule(
+ action: .space,
+ aliases: ["little gap"],
+ isEnabled: false
+ ),
+ ]
+
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("First literal drop down second"),
+ "First\nsecond"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("literal tab"),
+ "literal tab"
+ )
+ XCTAssertEqual(
+ ASRService.applySpokenPunctuationFormatting("literal little gap"),
+ "literal little gap"
+ )
+ }
+ }
+
+ func testSpokenFormattingActionAliasesRejectPunctuationAndActionConflicts() {
+ self.withRestoredDefaults(keys: self.punctuationFormattingDefaultsKeys) {
+ let settings = SettingsStore.shared
+ settings.spokenFormattingActionRules = [
+ SettingsStore.SpokenFormattingActionRule(
+ action: .newLine,
+ aliases: ["comma", "shared action", "drop down"]
+ ),
+ SettingsStore.SpokenFormattingActionRule(
+ action: .newParagraph,
+ aliases: ["shared action", "paragraph break"]
+ ),
+ ]
+
+ let rules = settings.spokenFormattingActionRules
+ XCTAssertEqual(rules.first { $0.action == .newLine }?.aliases, ["shared action", "drop down"])
+ XCTAssertEqual(rules.first { $0.action == .newParagraph }?.aliases, ["paragraph break"])
+
+ UserDefaults.standard.set(true, forKey: self.autoConvertPunctuationEnabledKey)
+ XCTAssertEqual(ASRService.applySpokenPunctuationFormatting("literal comma"), ",")
+ XCTAssertEqual(ASRService.applySpokenPunctuationFormatting("literal shared action"), "\n")
+ }
+ }
+
+ func testSpokenFormattingActionRulesRoundTripAndLegacyBackupsPreserveCurrentRules() async throws {
+ let defaults = UserDefaults.standard
+ let originalValue = defaults.object(forKey: self.spokenFormattingActionRulesKey)
+ defer {
+ if let originalValue {
+ defaults.set(originalValue, forKey: self.spokenFormattingActionRulesKey)
+ } else {
+ defaults.removeObject(forKey: self.spokenFormattingActionRulesKey)
+ }
+ }
+
+ let settings = SettingsStore.shared
+ let backedUpRules = [
+ SettingsStore.SpokenFormattingActionRule(
+ action: .newLine,
+ aliases: ["line break"]
+ ),
+ SettingsStore.SpokenFormattingActionRule(
+ action: .tab,
+ aliases: ["indent"],
+ isEnabled: false
+ ),
+ ]
+ settings.spokenFormattingActionRules = backedUpRules
+
+ let document = await BackupService.shared.makeBackupDocument()
+ let encoded = try BackupService.shared.encode(document)
+ let decoded = try BackupService.shared.decode(encoded)
+ XCTAssertEqual(decoded.settings.spokenFormattingActionRules, settings.spokenFormattingActionRules)
+
+ settings.spokenFormattingActionRules = SettingsStore.defaultSpokenFormattingActionRules
+ settings.restore(from: decoded.settings)
+ XCTAssertEqual(settings.spokenFormattingActionRules, decoded.settings.spokenFormattingActionRules)
+
+ var root = try XCTUnwrap(JSONSerialization.jsonObject(with: encoded) as? [String: Any])
+ var encodedSettings = try XCTUnwrap(root["settings"] as? [String: Any])
+ encodedSettings.removeValue(forKey: "spokenFormattingActionRules")
+ root["settings"] = encodedSettings
+ let legacyBackup = try BackupService.shared.decode(JSONSerialization.data(withJSONObject: root))
+ XCTAssertNil(legacyBackup.settings.spokenFormattingActionRules)
+
+ let rulesBeforeLegacyRestore = [
+ SettingsStore.SpokenFormattingActionRule(
+ action: .newParagraph,
+ aliases: ["keep this paragraph"]
+ ),
+ ]
+ settings.spokenFormattingActionRules = rulesBeforeLegacyRestore
+ let normalizedRulesBeforeLegacyRestore = settings.spokenFormattingActionRules
+ settings.restore(from: legacyBackup.settings)
+ XCTAssertEqual(settings.spokenFormattingActionRules, normalizedRulesBeforeLegacyRestore)
+ }
+}
+
@MainActor
final class OverlayFailureStateTests: XCTestCase {
func testCustomNonRetryableMessage() {