gpt4 book ai didi

swift - 适用于 Swift 的 iOS/Mac OS 流畅匹配框架?

转载 作者:可可西里 更新时间:2023-11-01 01:44:21 24 4
gpt4 key购买 nike

是否有适用于 Swift 代码的流畅匹配 API?领先的 Objective-C 匹配器候选者似乎是 OCHamcrest 和 Expecta,它们都依赖于复杂的宏,而这些宏 ( as per the docs ) 对 Swift 代码不可用,例如

#define HC_assertThat(actual, matcher)  \
HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__)

(奥哈姆克雷斯特)

#define EXP_expect(actual) _EXP_expect(self, __LINE__, __FILE__, ^id{ return EXPObjectify((actual)); })

(预期)

是否有另一种可以与 Swift 一起使用的替代方案,或者是否有某种方法可以包装其中一个或另一个以便它们可以与 Swift 一起使用?


预计到达时间:对于 future 的读者——我查看了SwiftHamcrest (根据 Jon Reid's answer )但目前我已经选择了 Quick/Nimble .

最佳答案

复杂的预处理器宏没有被翻译成它们的 Swift 替代品。 Apple 有一个讨论 Swift 的博客,in which they described on how they made the assert function .

第一个宏很容易做成一个Swift函数

#define HC_assertThat(actual, matcher)  \
HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__)

在 Swift 中:

func HC_assertThat(caller: AnyObject, actual: String, matcher: String, file: String = __FILE__, line: UWord = __LINE__) {
HC_assertThatWithLocation(caller, actual, matcher, file.fileSystemRepresentation, Int32(line))
}

#define EXP_expect(actual) _EXP_expect(self, __LINE__, __FILE__, ^id{ return EXPObjectify((actual)); })

在 Swift 中:

func EXP_expect(caller: AnyObject, actual: String, line: UWord = __LINE__, file: String = __FILE__) {
_EXP_expect(caller, Int32(line), file.fileSystemRepresentation, ({
return EXPObjectify(caller)
})
}

请注意,我是在猜测您要传递给预处理器函数的内容。

关于swift - 适用于 Swift 的 iOS/Mac OS 流畅匹配框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24480964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com