Skip to content

Commit

Permalink
Merge pull request #37 from ensan-hcl/test/async
Browse files Browse the repository at this point in the history
[Test] @mainactorのテストケースクラスをasyncなtestケースに変更
  • Loading branch information
ensan-hcl authored Feb 19, 2024
2 parents 83535f1 + d13341c commit f4e2af3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import KanaKanjiConverterModule

@MainActor final class CandidateTests: XCTestCase {
final class CandidateTests: XCTestCase {
// テンプレートのパース
func testParseTemplate() throws {
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import KanaKanjiConverterModule

@MainActor final class ConverterTests: XCTestCase {
final class ConverterTests: XCTestCase {
func requestOptions() -> ConvertRequestOptions {
ConvertRequestOptions(
N_best: 5,
Expand All @@ -31,13 +31,13 @@ import XCTest
}

// 変換されてはいけないケースを示す
func testMustNotCases() throws {
func testMustNotCases() async throws {
do {
// 改行文字に対して本当に改行が入ってしまうケース
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
var c = ComposingText()
c.insertAtCursorPosition("\\n", inputStyle: .direct)
let results = converter.requestCandidates(c, options: requestOptions())
let results = await converter.requestCandidates(c, options: requestOptions())
XCTAssertFalse(results.mainResults.contains(where: {$0.text == "\n"}))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@testable import KanaKanjiConverterModule
import XCTest

@MainActor final class EmailAddressConversionTests: XCTestCase {
final class EmailAddressConversionTests: XCTestCase {
func makeDirectInput(direct input: String) -> ComposingText {
ComposingText(
convertTargetCursorPosition: input.count,
Expand All @@ -18,11 +18,11 @@ import XCTest
)
}

func testtoEmailAddressCandidates() throws {
func testtoEmailAddressCandidates() async throws {
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "azooKey@")
let result = converter.toEmailAddressCandidates(input)
let result = await converter.toEmailAddressCandidates(input)
XCTAssertFalse(result.isEmpty)
XCTAssertTrue(result.contains(where: {$0.text == "azooKey@gmail.com"}))
XCTAssertTrue(result.contains(where: {$0.text == "azooKey@icloud.com"}))
Expand All @@ -31,9 +31,9 @@ import XCTest
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "my.dev_az@")
let result = converter.toEmailAddressCandidates(input)
let result = await converter.toEmailAddressCandidates(input)
XCTAssertFalse(result.isEmpty)
XCTAssertTrue(result.contains(where: {$0.text == "my.dev_az@gmail.com"}))
XCTAssertTrue(result.contains(where: {$0.text == "my.dev_az@icloud.com"}))
Expand All @@ -42,9 +42,9 @@ import XCTest
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "@")
let result = converter.toEmailAddressCandidates(input)
let result = await converter.toEmailAddressCandidates(input)
XCTAssertFalse(result.isEmpty)
XCTAssertTrue(result.contains(where: {$0.text == "@gmail.com"}))
XCTAssertTrue(result.contains(where: {$0.text == "@icloud.com"}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@testable import KanaKanjiConverterModule
import XCTest

@MainActor final class UnicodeConversionTests: XCTestCase {
final class UnicodeConversionTests: XCTestCase {
func makeDirectInput(direct input: String) -> ComposingText {
ComposingText(
convertTargetCursorPosition: input.count,
Expand All @@ -18,53 +18,53 @@ import XCTest
)
}

func testFromUnicode() throws {
func testFromUnicode() async throws {
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "U+3042")
let result = converter.unicodeCandidates(input)
let result = await converter.unicodeCandidates(input)
XCTAssertEqual(result.count, 1)
XCTAssertEqual(result[0].text, "")
}
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "U+1F607")
let result = converter.unicodeCandidates(input)
let result = await converter.unicodeCandidates(input)
XCTAssertEqual(result.count, 1)
XCTAssertEqual(result[0].text, "😇")
}
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "u+3042")
let result = converter.unicodeCandidates(input)
let result = await converter.unicodeCandidates(input)
XCTAssertEqual(result.count, 1)
XCTAssertEqual(result[0].text, "")
}
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "U3042")
let result = converter.unicodeCandidates(input)
let result = await converter.unicodeCandidates(input)
XCTAssertEqual(result.count, 1)
XCTAssertEqual(result[0].text, "")
}
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "u3042")
let result = converter.unicodeCandidates(input)
let result = await converter.unicodeCandidates(input)
XCTAssertEqual(result.count, 1)
XCTAssertEqual(result[0].text, "")
}
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "U+61")
let result = converter.unicodeCandidates(input)
let result = await converter.unicodeCandidates(input)
XCTAssertEqual(result.count, 1)
XCTAssertEqual(result[0].text, "a")
}
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "U+189")
let result = converter.unicodeCandidates(input)
let result = await converter.unicodeCandidates(input)
XCTAssertEqual(result.count, 1)
XCTAssertEqual(result[0].text, "Ɖ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@testable import KanaKanjiConverterModule
import XCTest

@MainActor final class WarekiConversionTests: XCTestCase {
final class WarekiConversionTests: XCTestCase {
func makeDirectInput(direct input: String) -> ComposingText {
ComposingText(
convertTargetCursorPosition: input.count,
Expand All @@ -18,11 +18,11 @@ import XCTest
)
}

func testSeireki2Wareki() throws {
func testSeireki2Wareki() async throws {
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "2019ねん")
let result = converter.toWarekiCandidates(input)
let result = await converter.toWarekiCandidates(input)
XCTAssertEqual(result.count, 2)
if result.count == 2 {
XCTAssertEqual(result[0].text, "令和元年")
Expand All @@ -31,39 +31,39 @@ import XCTest
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "2020ねん")
let result = converter.toWarekiCandidates(input)
let result = await converter.toWarekiCandidates(input)
XCTAssertEqual(result.count, 1)
if result.count == 1 {
XCTAssertEqual(result[0].text, "令和2年")
}
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "2001ねん")
let result = converter.toWarekiCandidates(input)
let result = await converter.toWarekiCandidates(input)
XCTAssertEqual(result.count, 1)
if result.count == 1 {
XCTAssertEqual(result[0].text, "平成13年")
}
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "1945ねん")
let result = converter.toWarekiCandidates(input)
let result = await converter.toWarekiCandidates(input)
XCTAssertEqual(result.count, 1)
if result.count == 1 {
XCTAssertEqual(result[0].text, "昭和20年")
}
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "9999ねん")
let result = converter.toWarekiCandidates(input)
let result = await converter.toWarekiCandidates(input)
XCTAssertEqual(result.count, 1)
if result.count == 1 {
XCTAssertEqual(result[0].text, "令和7981年")
Expand All @@ -72,77 +72,77 @@ import XCTest

// invalid cases
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "せいれき2001ねん")
let result = converter.toWarekiCandidates(input)
let result = await converter.toWarekiCandidates(input)
XCTAssertTrue(result.isEmpty)
}
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "1582ねん")
let result = converter.toWarekiCandidates(input)
let result = await converter.toWarekiCandidates(input)
XCTAssertTrue(result.isEmpty)
}
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "10000ねん")
let result = converter.toWarekiCandidates(input)
let result = await converter.toWarekiCandidates(input)
XCTAssertTrue(result.isEmpty)
}

}

func testWareki2Seireki() throws {
func testWareki2Seireki() async throws {
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = ComposingText(
convertTargetCursorPosition: 8,
input: "れいわがんねん".map {.init(character: $0, inputStyle: .direct)},
convertTarget: "れいわがんねん"
)
let result = converter.toSeirekiCandidates(input)
let result = await converter.toSeirekiCandidates(input)
XCTAssertEqual(result.count, 1)
if result.count == 1 {
XCTAssertEqual(result[0].text, "2019年")
}
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = ComposingText(
convertTargetCursorPosition: 8,
input: "れいわ1ねん".map {.init(character: $0, inputStyle: .direct)},
convertTarget: "れいわ1ねん"
)
let result = converter.toSeirekiCandidates(input)
let result = await converter.toSeirekiCandidates(input)
XCTAssertEqual(result.count, 1)
if result.count == 1 {
XCTAssertEqual(result[0].text, "2019年")
}
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = ComposingText(
convertTargetCursorPosition: 8,
input: "しょうわ25ねん".map {.init(character: $0, inputStyle: .direct)},
convertTarget: "しょうわ25ねん"
)
let result = converter.toSeirekiCandidates(input)
let result = await converter.toSeirekiCandidates(input)
XCTAssertEqual(result.count, 1)
if result.count == 1 {
XCTAssertEqual(result[0].text, "1950年")
}
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = ComposingText(
convertTargetCursorPosition: 8,
input: "めいじ9ねん".map {.init(character: $0, inputStyle: .direct)},
convertTarget: "めいじ9ねん"
)
let result = converter.toSeirekiCandidates(input)
let result = await converter.toSeirekiCandidates(input)
XCTAssertEqual(result.count, 1)
if result.count == 1 {
XCTAssertEqual(result[0].text, "1876年")
Expand All @@ -151,16 +151,16 @@ import XCTest

// invalid cases
do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "れいわ100ねん")
let result = converter.toSeirekiCandidates(input)
let result = await converter.toSeirekiCandidates(input)
XCTAssertTrue(result.isEmpty)
}

do {
let converter = KanaKanjiConverter()
let converter = await KanaKanjiConverter()
let input = makeDirectInput(direct: "けいおう5ねん")
let result = converter.toSeirekiCandidates(input)
let result = await converter.toSeirekiCandidates(input)
XCTAssertTrue(result.isEmpty)
}
}
Expand Down

0 comments on commit f4e2af3

Please sign in to comment.