空手道比赛包含深度不能像您预期的那样工作
Karate match contains deep not working as you would expect
我们来自这里:https://github.com/intuit/karate#match-contains-deep
正如它所说:
This modifies the behavior of match contains so that nested lists or objects are processed for a "deep contains" match, ..., you only want to check for some values in the various "trees" of data
所以让我们试着玩一下,找到一些 {e: 5} 会在树深处的某个地方,当 original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
Feature: Match contains deep
# match contains deep test (works ok, but this is not "deep" by any stretch of imagination, this is guiding the whole path in the search)
Scenario: match contains deep test modified original
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { d: { e: 5 } }
* match original contains deep expected
#Thats was not deep, this is deep (fails, and this is what anyone would understand by "deep")
Scenario: match contains deep
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { e: 5 }
* match original contains deep expected
#So you dont need deep (fails)
Scenario: match contains test modified original without deep
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { d: { e: 5 } }
* match original contains expected
#So maybe it works with any (fails)
Scenario: match contains test modified original
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { e: 5 }
* match original contains any expected
#Maybe I'm tripping with syntax (fails)
Scenario: match contains deep test my test #2
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = e: 5
* match original contains deep expected
#So maybe I'm tripping with syntax and semantics, and its any (fails)
Scenario: match contains deep test my test #2
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = e: 5
* match original contains any expected
所以,要么我没有真正理解它,要么它没有像人们期望的那样工作,即我想检查放置在树中任何位置的现有键值对。
如果有人能对此有所启发,那就太好了。正如我所看到的,@PeterThomas 正在回答大部分标有 Karate 的问题,我要感谢他为将这个工具交到社区手中所做的巨大努力。
好吧,作为该工具的创建者,我就是这样定义“深度”的,所以我想您必须处理它 ;) 顺便说一句,您是第一个发现它具有误导性的人 - 老实说意见,它确实按您期望的方式工作。你有 JSON 的“子集” - 但你仍然想“修复”路径。这就是大多数人想要的,因为当您处理 JSON 时,您永远不希望出现“惊喜”,例如某些值跳来跳去并出现在其他地方。
也就是说,您似乎在寻找 JsonPath:
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* match original..* contains deep { e: 5 }
我把它作为练习留给你弄清楚它是如何工作的。但请随时寻求提示:P
@Greco,对不起,聚会迟到了你是对的,最初我还认为 deep 可以在任何地方找到键值对,但遗憾的是它不是那样的。
我理解这些术语的方式是:
包含 - 在根对象中找到提到的键,但它们的值完全匹配。
包含深层 - 在根对象中找到提到的键,然后可以允许这些键对其值进行部分匹配,就像包含允许根对象进行部分匹配一样。
正如@Peter所说,你必须形成一条路径,但它可以到达任何级别。
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: {f:5,g:6} } }
* def expected = { d: { e: {f:5} } }
* match original contains deep expected
我们来自这里:https://github.com/intuit/karate#match-contains-deep
正如它所说:
This modifies the behavior of match contains so that nested lists or objects are processed for a "deep contains" match, ..., you only want to check for some values in the various "trees" of data
所以让我们试着玩一下,找到一些 {e: 5} 会在树深处的某个地方,当 original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
Feature: Match contains deep
# match contains deep test (works ok, but this is not "deep" by any stretch of imagination, this is guiding the whole path in the search)
Scenario: match contains deep test modified original
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { d: { e: 5 } }
* match original contains deep expected
#Thats was not deep, this is deep (fails, and this is what anyone would understand by "deep")
Scenario: match contains deep
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { e: 5 }
* match original contains deep expected
#So you dont need deep (fails)
Scenario: match contains test modified original without deep
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { d: { e: 5 } }
* match original contains expected
#So maybe it works with any (fails)
Scenario: match contains test modified original
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { e: 5 }
* match original contains any expected
#Maybe I'm tripping with syntax (fails)
Scenario: match contains deep test my test #2
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = e: 5
* match original contains deep expected
#So maybe I'm tripping with syntax and semantics, and its any (fails)
Scenario: match contains deep test my test #2
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = e: 5
* match original contains any expected
所以,要么我没有真正理解它,要么它没有像人们期望的那样工作,即我想检查放置在树中任何位置的现有键值对。
如果有人能对此有所启发,那就太好了。正如我所看到的,@PeterThomas 正在回答大部分标有 Karate 的问题,我要感谢他为将这个工具交到社区手中所做的巨大努力。
好吧,作为该工具的创建者,我就是这样定义“深度”的,所以我想您必须处理它 ;) 顺便说一句,您是第一个发现它具有误导性的人 - 老实说意见,它确实按您期望的方式工作。你有 JSON 的“子集” - 但你仍然想“修复”路径。这就是大多数人想要的,因为当您处理 JSON 时,您永远不希望出现“惊喜”,例如某些值跳来跳去并出现在其他地方。
也就是说,您似乎在寻找 JsonPath:
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* match original..* contains deep { e: 5 }
我把它作为练习留给你弄清楚它是如何工作的。但请随时寻求提示:P
@Greco,对不起,聚会迟到了你是对的,最初我还认为 deep 可以在任何地方找到键值对,但遗憾的是它不是那样的。 我理解这些术语的方式是:
包含 - 在根对象中找到提到的键,但它们的值完全匹配。 包含深层 - 在根对象中找到提到的键,然后可以允许这些键对其值进行部分匹配,就像包含允许根对象进行部分匹配一样。
正如@Peter所说,你必须形成一条路径,但它可以到达任何级别。
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: {f:5,g:6} } }
* def expected = { d: { e: {f:5} } }
* match original contains deep expected