XCTAssert for enum cases?

I'm trying to write tests for functions that return enum cases with associated values. Is there a less awkward way to write this:

if case MyEnum.someCase(value1: 42, value2: "hello") = testResult {
     // pass       
} else {

It would be nice if pattern matching was a bit more composable. Maybe case ... could return a boolean or something, or maybe I'm just thinking about this wrong.

XCTAssertEqual requires the thing being asserted to conform to Equatable. So, you can conform your enum to Equatable, then you can simply do XCTAssertEqual(testResult, .someCase(value1: 42, value2: hello)).

Yeah that would work, thanks.

Terms of Service

Privacy Policy

Cookie Policy