-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 47de6d8 Author: ShikiSuen <[email protected]> Date: Sat Jun 3 19:47:10 2023 +0800 Extend ability for handing JSON dictionaries. (#2) * Change format method. * Extend ability for handing JSON dictionaries.
- Loading branch information
Showing
9 changed files
with
246 additions
and
120 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,4 +227,3 @@ _TeamCity* | |
_UpgradeReport_Files/ | ||
__pycache__/ | ||
~$* | ||
Tests/TestD[Ii]ctData/convdict.plist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# SwiftFormat config compliant with Google Swift Guideline | ||
# https://google.github.io/swift/#control-flow-statements | ||
|
||
# Specify version used in a project | ||
|
||
--swiftversion 5.5 | ||
|
||
# Rules explicitly required by the guideline | ||
|
||
--rules \ | ||
blankLinesAroundMark, \ | ||
blankLinesAtEndOfScope, \ | ||
blankLinesAtStartOfScope, \ | ||
blankLinesBetweenScopes, \ | ||
braces, \ | ||
consecutiveBlankLines, \ | ||
consecutiveSpaces, \ | ||
duplicateImports, \ | ||
elseOnSameLine, \ | ||
emptyBraces, \ | ||
enumNamespaces, \ | ||
extensionAccessControl, \ | ||
hoistPatternLet, \ | ||
indent, \ | ||
leadingDelimiters, \ | ||
linebreakAtEndOfFile, \ | ||
markTypes, \ | ||
organizeDeclarations, \ | ||
redundantInit, \ | ||
redundantParens, \ | ||
redundantPattern, \ | ||
redundantRawValues, \ | ||
redundantType, \ | ||
redundantVoidReturnType, \ | ||
semicolons, \ | ||
sortedImports, \ | ||
sortedSwitchCases, \ | ||
spaceAroundBraces, \ | ||
spaceAroundBrackets, \ | ||
spaceAroundComments, \ | ||
spaceAroundGenerics, \ | ||
spaceAroundOperators, \ | ||
spaceAroundParens, \ | ||
spaceInsideBraces, \ | ||
spaceInsideBrackets, \ | ||
spaceInsideComments, \ | ||
spaceInsideGenerics, \ | ||
spaceInsideParens, \ | ||
todos, \ | ||
trailingClosures, \ | ||
trailingCommas, \ | ||
trailingSpace, \ | ||
typeSugar, \ | ||
void, \ | ||
wrap, \ | ||
wrapArguments, \ | ||
wrapAttributes, \ | ||
# | ||
# | ||
# Additional rules not mentioned in the guideline, but helping to keep the codebase clean | ||
# Quoting the guideline: | ||
# Common themes among the rules in this section are: | ||
# avoid redundancy, avoid ambiguity, and prefer implicitness over explicitness | ||
# unless being explicit improves readability and/or reduces ambiguity. | ||
# | ||
# | ||
andOperator, \ | ||
isEmpty, \ | ||
redundantBackticks, \ | ||
redundantBreak, \ | ||
redundantExtensionACL, \ | ||
redundantGet, \ | ||
redundantLetError, \ | ||
redundantNilInit, \ | ||
redundantObjc, \ | ||
redundantReturn, \ | ||
redundantSelf, \ | ||
strongifiedSelf | ||
|
||
|
||
# Options for basic rules | ||
|
||
--extensionacl on-declarations | ||
--funcattributes prev-line | ||
--indent 2 | ||
--maxwidth 100 | ||
--typeattributes prev-line | ||
--varattributes prev-line | ||
--voidtype tuple | ||
--wraparguments before-first | ||
--wrapparameters before-first | ||
--wrapcollections before-first | ||
--wrapreturntype if-multiline | ||
--wrapconditions after-first | ||
|
||
# Option for additional rules | ||
|
||
--self init-only | ||
|
||
# Excluded folders | ||
|
||
--exclude Pods,**/UNTESTED_TODO,vendor,fastlane | ||
|
||
# https://github.com/NoemiRozpara/Google-SwiftFormat-Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Swiftified by (c) 2022 and onwards The vChewing Project (MIT-NTL License). | ||
// Rebranded from (c) Nick Chen's Obj-C library "NCChineseConverter" (MIT License). | ||
/* | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
1. The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
2. No trademark license is granted to use the trade names, trademarks, service | ||
marks, or product names of Contributor, except as required to fulfill notice | ||
requirements above. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import Foundation | ||
import XCTest | ||
|
||
@testable import Hotenka | ||
|
||
private let packageRootPath = URL(fileURLWithPath: #file).pathComponents.prefix(while: { $0 != "Tests" }).joined( | ||
separator: "/" | ||
).dropFirst() | ||
|
||
private let testDataPath: String = packageRootPath + "/Tests/TestDictData/" | ||
|
||
extension HotenkaTests { | ||
func testGeneratingJSON() throws { | ||
NSLog("// Start loading from: \(packageRootPath)") | ||
let testInstance: HotenkaChineseConverter = .init(dictDir: testDataPath) | ||
NSLog("// Loading complete. Generating json dict file.") | ||
do { | ||
try JSONSerialization.data(withJSONObject: testInstance.dict, options: .sortedKeys).write(to: URL(fileURLWithPath: testDataPath + "convdict.json")) | ||
} catch { | ||
NSLog("// Error on writing strings to file: \(error)") | ||
} | ||
} | ||
|
||
func testSampleWithJSON() throws { | ||
NSLog("// Start loading json from: \(packageRootPath)") | ||
let testInstance2: HotenkaChineseConverter = .init(jsonDir: testDataPath + "convdict.json") | ||
NSLog("// Successfully loading json dictionary.") | ||
|
||
let oriString = "为中华崛起而读书" | ||
let result1 = testInstance2.convert(oriString, to: .zhHantTW) | ||
let result2 = testInstance2.convert(result1, to: .zhHantKX) | ||
let result3 = testInstance2.convert(result2, to: .zhHansJP) | ||
NSLog("// Results: \(result1) \(result2) \(result3)") | ||
XCTAssertEqual(result1, "為中華崛起而讀書") | ||
XCTAssertEqual(result2, "爲中華崛起而讀書") | ||
XCTAssertEqual(result3, "為中華崛起而読書") | ||
} | ||
} |
Oops, something went wrong.