-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update coverage utils * update test * update either test * update constvalue * update utils test * update BitString test * update coverage * update coverage * update collection uitils test * update utils coverage
- Loading branch information
Showing
18 changed files
with
851 additions
and
49 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,38 +1,38 @@ | ||
import Foundation | ||
|
||
public enum AssertError: Error { | ||
case assertionFailed | ||
public enum DebugCheckError: Error { | ||
case assertionFailed(String, file: StaticString, line: UInt) | ||
case unexpectedError(Error, file: StaticString, line: UInt) | ||
} | ||
|
||
public func debugCheck( | ||
_ condition: @autoclosure () throws -> Bool, file: StaticString = #file, line: UInt = #line | ||
) { | ||
) throws { | ||
#if DEBUG_ASSERT | ||
let res = Result { try condition() } | ||
switch res { | ||
case let .success(res): | ||
if !res { | ||
fatalError(file: file, line: line) | ||
let result = Result { try condition() } | ||
switch result { | ||
case let .success(isValid): | ||
if !isValid { | ||
throw DebugCheckError.assertionFailed("Assertion failed", file: file, line: line) | ||
} | ||
case let .failure(err): | ||
fatalError("\(err)", file: file, line: line) | ||
case let .failure(error): | ||
throw DebugCheckError.unexpectedError(error, file: file, line: line) | ||
} | ||
#endif | ||
} | ||
|
||
public func debugCheck( | ||
_ condition: @autoclosure () async throws -> Bool, file: StaticString = #file, | ||
line: UInt = #line | ||
) async { | ||
_ condition: @autoclosure () async throws -> Bool, file: StaticString = #file, line: UInt = #line | ||
) async throws { | ||
#if DEBUG_ASSERT | ||
let res = await Result { try await condition() } | ||
switch res { | ||
case let .success(res): | ||
if !res { | ||
fatalError(file: file, line: line) | ||
let result = await Result { try await condition() } | ||
switch result { | ||
case let .success(isValid): | ||
if !isValid { | ||
throw DebugCheckError.assertionFailed("Assertion failed", file: file, line: line) | ||
} | ||
case let .failure(err): | ||
fatalError("\(err)", file: file, line: line) | ||
case let .failure(error): | ||
throw DebugCheckError.unexpectedError(error, file: file, line: line) | ||
} | ||
#endif | ||
} |
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,22 @@ | ||
import Testing | ||
|
||
@testable import Utils | ||
|
||
struct ConstIntTests { | ||
@Test | ||
func constIntValues() { | ||
#expect(ConstInt0.value == 0) | ||
#expect(ConstInt1.value == 1) | ||
#expect(ConstInt2.value == 2) | ||
#expect(ConstInt3.value == 3) | ||
#expect(ConstIntMax.value == Int.max) | ||
#expect(ConstInt32.value == 32) | ||
#expect(ConstInt48.value == 48) | ||
#expect(ConstInt64.value == 64) | ||
#expect(ConstUInt96.value == 96) | ||
#expect(ConstUInt128.value == 128) | ||
#expect(ConstUInt144.value == 144) | ||
#expect(ConstUInt384.value == 384) | ||
#expect(ConstUInt784.value == 784) | ||
} | ||
} |
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,33 @@ | ||
import Foundation | ||
import Testing | ||
|
||
@testable import Utils | ||
|
||
struct DebugCheckTests { | ||
func awaitThrow(_ expression: () async throws -> some Any) async throws -> Bool { | ||
_ = try await expression() | ||
return true | ||
} | ||
|
||
func doesThrow(_ expression: () throws -> some Any) throws -> Bool { | ||
_ = try expression() | ||
return true | ||
} | ||
|
||
@Test | ||
func testDebugCheck() async throws { | ||
try #expect(doesThrow { | ||
try debugCheck(1 + 1 == 2) | ||
} == true) | ||
#expect(throws: DebugCheckError.self) { | ||
try debugCheck(1 + 1 == 3) | ||
} | ||
try await #expect(awaitThrow { | ||
try await debugCheck(1 + 1 == 2) | ||
} == true) | ||
|
||
await #expect(throws: DebugCheckError.self) { | ||
try await debugCheck(1 + 1 == 3) | ||
} | ||
} | ||
} |
Oops, something went wrong.