OpenCC // Swift Clang-Format.

This commit is contained in:
ShikiSuen 2022-04-03 12:50:51 +08:00
parent 9aa781ecfd
commit 5fba88cfeb
8 changed files with 408 additions and 401 deletions

View File

@ -7,7 +7,7 @@ let package = Package(
products: [
.library(
name: "OpenCC",
targets: ["OpenCC"]),
targets: ["OpenCC"])
],
targets: [
.target(

View File

@ -22,7 +22,11 @@ extension ChineseConverter {
}
func dict(_ name: ChineseConverter.DictionaryName) throws -> ConversionDictionary {
guard let path = bundle.path(forResource: name.description, ofType: "ocd2", inDirectory: DictionaryLoader.subdirectory) else {
guard
let path = bundle.path(
forResource: name.description, ofType: "ocd2",
inDirectory: DictionaryLoader.subdirectory)
else {
throw ConversionError.fileNotFound
}
return try DictionaryLoader.dictCache.value(for: path) {

View File

@ -1,4 +1,5 @@
import XCTest
@testable import OpenCC
let testCases: [(String, ChineseConverter.Options)] = [
@ -20,7 +21,8 @@ class OpenCCTests: XCTestCase {
func testConversion() throws {
func testCase(name: String, ext: String) -> String {
let url = Bundle.module.url(forResource: name, withExtension: ext, subdirectory: "testcases")!
let url = Bundle.module.url(
forResource: name, withExtension: ext, subdirectory: "testcases")!
return try! String(contentsOf: url)
}
for (name, opt) in testCases {
@ -54,7 +56,8 @@ class OpenCCTests: XCTestCase {
func testConversionPerformance() throws {
let cov = try converter(option: [.traditionalize, .twStandard, .twIdiom])
let url = Bundle.module.url(forResource: "zuozhuan", withExtension: "txt", subdirectory: "benchmark")!
let url = Bundle.module.url(
forResource: "zuozhuan", withExtension: "txt", subdirectory: "benchmark")!
// 1.9 MB, 624k word
let str = try String(contentsOf: url)
measure {