空手道比赛包含无法正常工作的深渊 [英] Karate match contains deep not working as you would expect

查看:64
本文介绍了空手道比赛包含无法正常工作的深渊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们来自这里: 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

因此,当 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
 

所以,要么我没有真正得到它,要么它没有按人们期望的那样工作,即我想检查放置在树中任何地方的现有键值对.

So, either I'm not really getting the thing, or it doesn't work as one would expect, i.e. I would like to check an existing key-value pair placed anywhere in the tree.

如果有人可以给它照亮,那就太好了.如我所见,@ PeterThomas回答了大多数用空手道标记的问题,我要感谢他为将这个工具交付社区而付出的巨大努力.

If someone can throw some light at it, that would be great. As I can see @PeterThomas is answering most of the questions tagged with Karate, I want to thank him for the great effort on putting this tool in the hands of the community.

推荐答案

作为工具的创建者,这就是我定义"deep"对象的方式.因此,我想您必须处理它;)顺便说一句,您是第一个发现它具有误导性的人-并且我诚实地认为,它确实可以按您期望的方式工作.您有子集"JSON-但是您仍然想修复"路径.这就是大多数人想要的,因为当您处理JSON时,您永远不需要惊喜".就像一些值跳来跳去,出现在其他地方.

Well as the creator of the tool, that's how I have defined "deep" so I guess you have to deal with it ;) You are the first ever to find it misleading, by the way - and in my honest opinion, it does work the way you expect. You have "subsets" of JSON - but you still do want to "fix" the path. And this is what most people want, because when you deal with JSON you never want "surprises" like some values jump around and appear somewhere else.

也就是说,您似乎正在寻找的是JsonPath:

That said, what you seem to be looking for is JsonPath:

* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* match original..* contains deep { e: 5 }

我将其留给您练习,以了解其工作原理.但是请随时提出提示:P

I leave it as an exercise to you to figure out how it works. But feel free to ask for hints :P

这篇关于空手道比赛包含无法正常工作的深渊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆