Skip to content

Commit

Permalink
Refactor some handlings and unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Mar 18, 2024
1 parent 0f04e78 commit 9273d51
Show file tree
Hide file tree
Showing 19 changed files with 7,529 additions and 7,498 deletions.
58 changes: 14 additions & 44 deletions Sources/Tekkon/Tekkon_SyllableComposer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,8 @@ public extension Tekkon {
receiveKey(fromPhonabet: translate(key: input))
return
}
if mapArayuruPinyinIntonation.keys.contains(input) {
if let theTone = mapArayuruPinyinIntonation[input] {
intonation = Phonabet(theTone)
}
if let theTone = mapArayuruPinyinIntonation[input] {
intonation = Phonabet(theTone)
} else {
// 為了防止 romajiBuffer 越敲越長帶來算力負擔,這裡讓它在要溢出時自動丟掉最早輸入的音頭。
let maxCount: Int = (parser == .ofWadeGilesPinyin) ? 7 : 6
Expand Down Expand Up @@ -262,15 +260,11 @@ public extension Tekkon {
default: break
}
if [.vowel, .intonation].contains(thePhone.type), "ㄓㄔㄕㄗㄘㄙ".doesHave(consonant.value) {
switch semivowel.value {
case "": semivowel.clear()
case "":
switch consonant {
case _ where "ㄓㄗ".doesHave(consonant.value): consonant = ""
case _ where "ㄔㄘ".doesHave(consonant.value): consonant = ""
case _ where "ㄕㄙ".doesHave(consonant.value): consonant = ""
default: break
}
switch (semivowel, consonant) {
case ("", _): semivowel.clear()
case ("", ""), ("", ""): consonant = ""
case ("", ""), ("", ""): consonant = ""
case ("", ""), ("", ""): consonant = ""
default: break
}
}
Expand Down Expand Up @@ -430,35 +424,11 @@ public extension Tekkon {
// 處理特殊情形。
switch incomingPhonabet.type {
case .semivowel:
switch consonant {
case "":
switch incomingPhonabet {
// 這裡不處理「ㄍㄧ」到「ㄑㄧ」的轉換,因為只有倚天26需要處理這個。
case "": consonant = "" // ㄍㄨ
case "": consonant = "" // ㄑㄩ
default: break
}
case "":
switch incomingPhonabet {
case "": consonant = "" // ㄐㄧ
case "": consonant = "" // ㄓㄨ
case "": consonant = "" // ㄐㄩ
default: break
}
case "":
switch incomingPhonabet {
case "": consonant = "" // ㄐㄧ
case "": consonant = "" // ㄓㄨ
case "": consonant = "" // ㄐㄩ
default: break
}
case "":
switch incomingPhonabet {
case "": consonant = "" // ㄒㄧ
case "": consonant = "" // ㄕㄨ
case "": consonant = "" // ㄒㄩ
default: break
}
// 這裡不處理「ㄍㄧ」到「ㄑㄧ」的轉換,因為只有倚天26需要處理這個。
switch (consonant, incomingPhonabet) {
case ("", ""), ("", ""): consonant = ""
case ("", ""), ("", ""), ("", ""): consonant = ""
case ("", ""), ("", ""): consonant = ""
default: break
}
if incomingPhonabet == "" {
Expand Down Expand Up @@ -671,10 +641,10 @@ public extension Tekkon {
} else if semivowel != "", vowel == "" {
vowel.clear()
strReturn = ""
} else if !semivowel.isEmpty {
} else if !semivowel.isEmpty || !"ㄐㄑㄒ".doesHave(consonant.value) {
strReturn = ""
} else {
strReturn = "ㄐㄑㄒ".doesHave(consonant.value) ? "" : ""
strReturn = ""
}
case "u":
if semivowel == "", vowel != "" {
Expand Down
2 changes: 2 additions & 0 deletions Tests/TekkonTests/BasicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ final class TekkonTestsBasic: XCTestCase {
// Testing tool functions
XCTAssertEqual(Tekkon.restoreToneOneInPhona(target: "ㄉㄧㄠ"), "ㄉㄧㄠ1")
XCTAssertEqual(Tekkon.cnvPhonaToTextbookStyle(target: "ㄓㄜ˙"), "˙ㄓㄜ")
XCTAssertEqual(Tekkon.cnvPhonaToHanyuPinyin(targetJoined: "ㄍㄢˋ"), "gan4")
XCTAssertEqual(Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: "起(qi3)居(ju1)"), "起(qǐ)居(jū)")
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(targetJoined: "bian4-le5-tian1"), "ㄅㄧㄢˋ-ㄌㄜ˙-ㄊㄧㄢ")
// 測試這種情形:「如果傳入的字串不包含任何半形英數內容的話,那麼應該直接將傳入的字串原樣返回」。
XCTAssertEqual(Tekkon.cnvHanyuPinyinToPhona(targetJoined: "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ"), "ㄅㄧㄢˋ-˙ㄌㄜ-ㄊㄧㄢ")
Expand Down
Loading

0 comments on commit 9273d51

Please sign in to comment.