空手道比赛包含无法正常工作的深渊

时间:2020-10-15 12:42:43

标签: karate

我们来自这里:https://github.com/intuit/karate#match-contains-deep

声明:

这会修改匹配包含的行为,以便为“深度包含”匹配处理嵌套列表或对象,...,您只想检查数据的各种“树”中的某些值

因此,让我们试着玩一下,找到一些{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回答了大多数用空手道标记的问题,我要感谢他为将这个工具交付社区而付出的巨大努力。

1 个答案:

答案 0 :(得分:1)

作为该工具的创建者,这就是我定义“深层”的方式,因此我想您必须加以解决;)顺便说一句,您是第一个发现它具有误导性的人-在我看来,它确实按照您期望的方式工作。您具有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