Scala Koans 中的 === (triple-equals) 运算符是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10489548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the === (triple-equals) operator in Scala Koans?
提问by pohl
I started working my way through the Scala Koans, which is organized around a suite of unit tests with blanks that one needs to fill in. (This idea was modeled after a similar Ruby Koans project.) You start the sbt tool running a test, and it admonishes:
我开始研究Scala Koans,它围绕一组单元测试组织,其中包含需要填写的空白。(这个想法模仿了一个类似的 Ruby Koans 项目。)你启动 sbt 工具运行一个测试,它告诫说:
[info] + ***************************************** [info] + [info] + [info] + [info] + Please meditate on koan "None equals None" of suite "AboutEmptyValues" [info] + [info] + [info] + [info] + *****************************************
...and so you go look at this unit test and it says:
...所以你去看看这个单元测试,它说:
test("None equals None") {
assert(None === __)
}
...and, after meditation, you realize that you should fill in the blank like this:
……而且,在冥想之后,你意识到你应该像这样填空:
test("None equals None") {
assert(None === None)
}
...and then it moves on to the next unit test.
...然后它继续进行下一个单元测试。
My question, though, is what is this ===operator? I can't seem to find it anywhere. Is this a DSL operator defined in the Scala Koans project itself? Or is it part of the ScalaTest framework? Or in Scala proper?
不过,我的问题是这个===运算符是什么?我似乎无法在任何地方找到它。这是 Scala Koans 项目本身定义的 DSL 运算符吗?或者它是 ScalaTest 框架的一部分?还是在 Scala 中正确?
回答by rolve
This is the triple-equals operator from ScalaTest. Have a look at this page: Getting Started with FunSuite. It says:
这是来自ScalaTest的三重等号运算符。看看这个页面:FunSuite 入门。它说:
ScalaTest lets you use Scala's assertion syntax, but defines a triple equals operator (===) to give you better error messages. The following code would give you an error indicating only that an assertion failed:
assert(1 == 2)Using triple equals instead would give you the more informative error message, "1 did not equal 2":
assert(1 === 2)
ScalaTest 允许您使用 Scala 的断言语法,但定义了一个三等号运算符 (===) 以提供更好的错误消息。下面的代码会给你一个错误,表明断言失败:
assert(1 == 2)改用三重等于会给您提供更多信息的错误消息,“1 不等于 2”:
assert(1 === 2)

