Karate 忽略和呈现是同一件事吗?

Karate 忽略和呈现是同一件事吗?,karate,Karate,在什么情况下,我想使用#ignore而不是#present,反之亦然?还是完全相同 我第一次读到这些文件时,我以为下面的内容会通过,但事实并非如此。编辑添加:这在空手道0.9.0中失败,但在0.8.0中通过 * def foo = {a: 1} * match foo == {a: 1, b: "#ignore"} 这些确实通过了: * def foo = {a: 1} * match foo == {a: 1, b: "##ignore"} * match foo == {a: 1, b:

在什么情况下,我想使用
#ignore
而不是
#present
,反之亦然?还是完全相同

我第一次读到这些文件时,我以为下面的内容会通过,但事实并非如此。编辑添加:这在空手道0.9.0中失败,但在0.8.0中通过

* def foo = {a: 1}
* match foo == {a: 1, b: "#ignore"}
这些确实通过了:

* def foo = {a: 1}
* match foo == {a: 1, b: "##ignore"}
* match foo == {a: 1, b: "##present"}

是,如果要匹配密钥不存在或为null,请使用双哈希:

* def foo = { a: 1 }
* match foo == { a: 1, b: '##ignore' }
* match foo == { a: 1, b: '#notpresent' }

* def foo = { a: 1, b: null }
* match foo == { a: 1, b: '##ignore' }
* match foo == { a: 1, b: '#present' }

* def foo = { a: 1, b: 'bar' }
* match foo == { a: 1, b: '##ignore' }
* match foo == { a: 1, b: '#present' }
不,
#ignore
#present
不具有相同的行为

空手道0.9.0中有一个bug导致他们的行为相同,但事实并非如此

#忽略
应与是否存在密钥相匹配

# This case would NOT match with '#present'
# This case fails in Karate 0.9.0 due to a bug
* def foo = {}
* match foo == { a: '#ignore' }

# These cases would also match with '#present'
* def foo = {a: null}
* match foo == { a: '#ignore' }
* def foo = {a: "bar"}
* match foo == { a: '#ignore' }

谢谢你,彼得。您是否同意编辑
#ignore
文档?当前的
#
文档非常清晰。@AlexJ感谢您展示这些边缘案例,非常感谢: