Add workaround to fix note language recognition and reduce wasteful translation requests
This commit is contained in:
26
damusTests/BlocksExtensionTests.swift
Normal file
26
damusTests/BlocksExtensionTests.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// BlocksExtensionTests.swift
|
||||
// damusTests
|
||||
//
|
||||
// Created by Terry Yiu on 1/8/24.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import NaturalLanguage
|
||||
@testable import damus
|
||||
|
||||
final class BlocksExtensionTests: XCTestCase {
|
||||
|
||||
func testLanguageHypothesisIsCorrectWithRightSingleQuotationMark() throws {
|
||||
let note = try XCTUnwrap(NdbNote.owned_from_json(json: test_english_text_note_with_right_single_quotation_mark))
|
||||
let blocks = note.blocks(test_keypair)
|
||||
XCTAssertEqual(blocks.languageHypothesis, NLLanguage.english)
|
||||
}
|
||||
|
||||
func testLanguageHypothesisIsCorrectWithNonEnglishLocale() throws {
|
||||
let note = try XCTUnwrap(NdbNote.owned_from_json(json: test_japanese_text_note))
|
||||
let blocks = note.blocks(test_keypair)
|
||||
XCTAssertEqual(blocks.languageHypothesis, NLLanguage.japanese)
|
||||
}
|
||||
|
||||
}
|
||||
40
damusTests/Util/TranslatorTests.swift
Normal file
40
damusTests/Util/TranslatorTests.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// TranslatorTests.swift
|
||||
// damusTests
|
||||
//
|
||||
// Created by Terry Yiu on 1/8/24.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import damus
|
||||
|
||||
final class TranslatorTests: XCTestCase {
|
||||
|
||||
func testShouldTranslateWhenLanguagesAreDifferent() throws {
|
||||
let userSettingsStore = UserSettingsStore()
|
||||
userSettingsStore.translation_service = .purple
|
||||
let translator = Translator(userSettingsStore, purple: DamusPurple(environment: .local_test, keypair: test_keypair))
|
||||
|
||||
XCTAssertTrue(translator.shouldTranslate(from: "en", to: "es"))
|
||||
XCTAssertTrue(translator.shouldTranslate(from: "es", to: "fr"))
|
||||
}
|
||||
|
||||
func testShouldNotTranslateWhenLanguagesAreTheSame() throws {
|
||||
let userSettingsStore = UserSettingsStore()
|
||||
userSettingsStore.translation_service = .purple
|
||||
let translator = Translator(userSettingsStore, purple: DamusPurple(environment: .local_test, keypair: test_keypair))
|
||||
|
||||
XCTAssertFalse(translator.shouldTranslate(from: "en", to: "en"))
|
||||
XCTAssertFalse(translator.shouldTranslate(from: "es", to: "es"))
|
||||
}
|
||||
|
||||
func testShouldNotTranslateWhenNoTranslationServiceSelected() throws {
|
||||
let userSettingsStore = UserSettingsStore()
|
||||
userSettingsStore.translation_service = .none
|
||||
let translator = Translator(userSettingsStore, purple: DamusPurple(environment: .local_test, keypair: test_keypair))
|
||||
|
||||
XCTAssertFalse(translator.shouldTranslate(from: "en", to: "es"))
|
||||
XCTAssertFalse(translator.shouldTranslate(from: "es", to: "fr"))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user