Skip to content

Commit

Permalink
Await async process in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Oct 2, 2024
1 parent 1884efd commit c186af3
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions Tests/Sources/Models/EditorCounterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import Testing
}


@Test func allRequiredInfo() throws {
@Test func allRequiredInfo() async throws {

let source = Source(string: self.testString, selectedRange: NSRange(11..<21))

Expand All @@ -77,23 +77,24 @@ import Testing
counter.invalidateContent()
counter.invalidateSelection()

withKnownIssue("values will be updated asynchronously (This is the issue on the test side.)") {
#expect(counter.result.lines.entire == 3)
#expect(counter.result.characters.entire == 31)
#expect(counter.result.words.entire == 6)

#expect(counter.result.characters.selected == 9)
#expect(counter.result.lines.selected == 1)
#expect(counter.result.words.selected == 2)

#expect(counter.result.location == 10)
#expect(counter.result.column == 0)
#expect(counter.result.line == 2)
}
// wait for async process
try await Task.sleep(for: .seconds(0.5))

#expect(counter.result.lines.entire == 3)
#expect(counter.result.characters.entire == 31)
#expect(counter.result.words.entire == 6)

#expect(counter.result.characters.selected == 9)
#expect(counter.result.lines.selected == 1)
#expect(counter.result.words.selected == 2)

#expect(counter.result.location == 10)
#expect(counter.result.column == 0)
#expect(counter.result.line == 2)
}


@Test func skipWholeText() throws {
@Test func skipWholeText() async throws {

let source = Source(string: self.testString, selectedRange: NSRange(11..<21))

Expand All @@ -106,19 +107,20 @@ import Testing
#expect(counter.result.characters.entire == nil)
#expect(counter.result.words.entire == nil)

withKnownIssue("values will be updated asynchronously (This is the issue on the test side.)") {
#expect(counter.result.lines.selected == 1)
#expect(counter.result.characters.selected == 9)
#expect(counter.result.words.selected == 2)

#expect(counter.result.location == 10)
#expect(counter.result.column == 0)
#expect(counter.result.line == 2)
}
// wait for async process
try await Task.sleep(for: .seconds(0.5))

#expect(counter.result.lines.selected == 1)
#expect(counter.result.characters.selected == 9)
#expect(counter.result.words.selected == 2)

#expect(counter.result.location == 10)
#expect(counter.result.column == 0)
#expect(counter.result.line == 2)
}


@Test func crlf() throws {
@Test func crlf() async throws {

let source = Source(string: "a\r\nb", selectedRange: NSRange(1..<4))

Expand All @@ -128,19 +130,20 @@ import Testing
counter.invalidateContent()
counter.invalidateSelection()

withKnownIssue("values will be updated asynchronously (This is the issue on the test side.)") {
#expect(counter.result.lines.entire == 2)
#expect(counter.result.characters.entire == 3)
#expect(counter.result.words.entire == 2)

#expect(counter.result.lines.selected == 2)
#expect(counter.result.characters.selected == 2)
#expect(counter.result.words.selected == 1)

#expect(counter.result.location == 1)
#expect(counter.result.column == 1)
#expect(counter.result.line == 1)
}
// wait for async process
try await Task.sleep(for: .seconds(0.5))

#expect(counter.result.lines.entire == 2)
#expect(counter.result.characters.entire == 3)
#expect(counter.result.words.entire == 2)

#expect(counter.result.lines.selected == 2)
#expect(counter.result.characters.selected == 2)
#expect(counter.result.words.selected == 1)

#expect(counter.result.location == 1)
#expect(counter.result.column == 1)
#expect(counter.result.line == 1)
}


Expand Down

0 comments on commit c186af3

Please sign in to comment.